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
RegEX
Supply a RegEx expression in the data-val-checkAgainst attribute to test the value against. RegEx expressions start with a prefix (regex: ), then a space and then the expression such as [4-9].Example:
<input type="text" name="regex1" data-val-required="1" data-val-checkAgainst="regex: [4-9]" /> <input type="text" name="regex2" data-val-required="1" data-val-checkAgainst="regex: ^[4-9]$" /> <input type="text" name="regex3" data-val-required="1" data-val-checkAgainst="regex: ^New( )(York|Hampshire|Mexico)$" />