Form Validation Toolkit

Validation Types

How many different ways or types of validation can we carry out.

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

Date Operators

Supply a date operator expression to compare against a date. 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:

'date: == d' - Checks if the value is equal to the date (d)
'date: != d' - Checks if the value is NOT equal to the date (d)
'date: > d' - Checks if the value is greater than the date (d)
'date: < d' - Checks if the value is less than the date (d)
'date: >= d' - Checks if the value is greater than or equal to the date (d)
'date: <= d' - Checks if the value is less than or equal to the date (d)
'date: {d && dd}' - Checks if the value is between the dates (d) and (d) - m and n being included
Example:
<input type="text" name="date1"  data-val-required="1"  data-val-checkAgainst="date: == 01/22/2012"  />
<input type="text" name="date2"  data-val-required="1"  data-val-checkAgainst="date: != 01/22/2012"  />
<input type="text" name="date3"  data-val-required="1"  data-val-checkAgainst="date: > 01/22/2012"  />
<input type="text" name="date4"  data-val-required="1"  data-val-checkAgainst="date: < 01/22/2012"  />
<input type="text" name="date5"  data-val-required="1"  data-val-checkAgainst="date: >= 01/22/2012"  />
<input type="text" name="date6"  data-val-required="1"  data-val-checkAgainst="date: <= 01/22/2012"  />
<input type="text" name="date7"  data-val-required="1"  data-val-checkAgainst="date: {01/22/2012 && 11/09/2012}"  />