Form Validation Toolkit

Data Type Tests



Minimum Steps to Validation:

1. Set the validation attributes of the input field
2. Attach (Initiate) the JavaScript validation process to the form (or the fields)

Dates

These are examples for date entries.
data-val-checkType="phone" can be specified as an attribute to check for valid date entries. Ddata formats are available for this type by supplying data-val-checkFormat="" to check various date format adherence.

Follow are the number data-val-checkFormat options:

'm/d/yy' - Allows these formats: 01/02/12 or 1/2/12
'mm/dd/yy' - Allows these format: 01/02/12
'm/d/yyyy' - Allows these formats: 01/02/2012 or 1/2/2012
'mm/dd/yyyy' - Allows these format: 01/02/2012
'M d, yy' - Allows these formats: Jan 2, 12 or January 02, 12
'M dd, yy' - Allows these formats: Jan 02, 12
'M d, yyyy' - Allows these formats: Jan 2, 2012 or January 02, 2012
'M dd, yyyy' - Allows these formats: Jan 02, 2012
'MM d, yy' - Allows these formats: January 2, 12 or January 02, 12
'MM dd, yy' - Allows these formats: January 02, 12
'MM d, yyyy' - Allows these formats: January 2, 2012 or January 02, 2012
'MM dd, yyyy' - Allows these formats: January 02, 2012

More than one options can be supplied by combining them in a conditional 'OR' logic:
data-val-checkFormat="m/d/yy||m/d/yyyy"

Example: (positive numbers)
<input type="text" name="date1" data-val-required="1" data-val-checkType="date" data-val-checkFormat="mm/dd/yyyy" />
<input type="text" name="date2" data-val-required="1" data-val-checkType="date" data-val-checkFormat="m/d/yy || M d, yy || MM d, yy"  />

<script>
	$('#data-type-test-form').initValidation();
</script>

The format below will accept m/d/yy, mm/d/yy and mm/dd/yy
The format below will only accept mm/dd/yy
The format below will accept m/d/yyyy, mm/d/yyyy and mm/dd/yyyy
The format below will only accept mm/dd/yyyy
The format below will accept M d, yy and M dd, yy
The format below will only accept M dd, yy
The format below will accept M d, yyyy and M dd, yyyy
The format below will only accept M dd, yy
The format below will accept MM d, yy and MM dd, yy
The format below will only accept MM dd, yy
The format below will accept MM d, yyyy and MM dd, yyyy
The format below will only accept MM dd, yyyy