- The Range attribute specified the minimum and maximum constraints for a numerical value.
- We can use this attribute to accepts the age of particular age group users.
Example 1 :
In the above example, we specified the minimum and the maximum parameter for the age field.
When this range is not adhered, validation message is shown.
Here we have not specified the Error Message. It will pick the default message.
On UI we supplied age as 19, which is one less than the minimum value of the range. The validation fails for the field and validation message is shown.
Example 2 :
In above example along with the range we have also specified the error message to display on UI.
Example 3 :
We can also pick the error message from resource file. The above code expects a resource file with name Multi.resx having a key Age_Validation which holds the validation message. When validation fails system picks the validation message from the resource file specified.
Watch Video :