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)

Numbers

These are examples for general numbers - whole and decimal.
data-val-checkType="number" can be specified as an attribute to check for a valid number. Data formats are available for this type by supplying data-val-checkFormat="" options to check for integers, floats, negative and positive numbers.

Follow are the number format options:

'num' - General numbers that can be whole, decimal, positive or negative
'neg' - Any negative number - whole or decimal
'pos' - Any positive number - whole or decimal
'int' - Integer or whole numbers only - negative or positive
'neg-int' - Negative integer or whole numbers only
'pos-int' - Positive integer or whole numbers only
'float' - Float or decimal numbers only - negative or positive
'neg-float' - Negative float or decimal numbers only
'pos-float' - Positive float or decimal numbers only

More than one options can be supplied by combining them in a conditional 'OR' logic:
data-val-checkFormat="pos-int||pos-float"

Example: (positive numbers)
<input type="text" data-val-error-text="Please supply a valid number." data-val-error-title="Number" data-val-required="1"  
	id="pos" name="pos" data-val-checkType="number"  data-val-checkFormat="pos"  />

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

Any Numbers

Positive Numbers

Negative Numbers

Mixed Number Example