Validation Types
How many different ways or types of validation can we carry out.- → Scenarios: When to Validation
- → Required Inputs
- → Min-Length Validation
- → Data Type Validation
- → Custom Expression Validation
Custom Expression Validation
Whether a field is required or not, a field can be checked against a number of custom expressions. If a field is not required, the custom expression validation is checked only if the input has value.The input attribute data-val-checkAgainst is used to specify a number pre-defined type of expressions.
You can test for the following types of custom expressions:
Equal To | Another Input | An Array | Numeric Operators | String Operators | Date Operators | RegEx Expression
Numeric Operators
Supply a numeric operator expression to compare against numbers. The input field's value must match the expression. Expressions start with a prefix (exp: ), then a space and then the operator such as ==, >=, etc.Follow are the numeric operator data-val-checkAgainst options:
'exp: == n' - Checks if the value is equal to the number (n)
'exp: != n' - Checks if the value is NOT equal to the number (n)
'exp: > n' - Checks if the value is greater than the number (n)
'exp: < n' - Checks if the value is less than the number (n)
'exp: >= n' - Checks if the value is greater than or equal to the number (n)
'exp: <= n' - Checks if the value is less than or equal to the number (n)
'exp: {m && n}' - Checks if the value is between the numbers (m) and (n) - m and n being included
Example:
<input type="text" name="numeric1" data-val-required="1" data-val-checkAgainst="exp: == 10" />
<input type="text" name="numeric2" data-val-required="1" data-val-checkAgainst="exp: != 10" />
<input type="text" name="numeric3" data-val-required="1" data-val-checkAgainst="exp: > 10" />
<input type="text" name="numeric4" data-val-required="1" data-val-checkAgainst="exp: < 10" />
<input type="text" name="numeric5" data-val-required="1" data-val-checkAgainst="exp: >= 10" />
<input type="text" name="numeric6" data-val-required="1" data-val-checkAgainst="exp: <= 10" />
<input type="text" name="numeric7" data-val-required="1" data-val-checkAgainst="exp: {10 && 20}" />