Contents |
Working with Validators
Validators are a standard way to check the user input. For example you may need to ensure that a given field contains a phone number in a given format.
Standard Validators
Here is a list of most common filters: integer, number, regexp
Syntax
Validators are specified as ng-validate attributes on user input widgets. Such as in this example:
Try typing text and numbers into the field and notice how the field changes color.
Writing your own Validators
Writing your own validator is easy; all one has to do is define a JavaScript function on the validators object. Then the function will become automatically available as a validator. The framework will pass in the input, which needs to be validated, as the first argument to your function. Any additional validator arguments are passed in as additional arguments to your function.
In this example we have written a upsTracikingNo validator. It validates only when the user enters valid UPS tracking number.