@workInProgress @ngdoc overview @name Developer Guide: Validators: Creating Angular Validators @description To create a custom validator, you simply add your validator code as a method onto the `angular.validator` object and provide input(s) for the validator function. Each input provided is treated as an argument to the validator function. Any additional inputs should be separated by commas. The following bit of pseudo-code shows how to set up a custom validator:
angular.validator('your_validator', function(input [,additional params]) {
[your validation code];
if ( [validation succeeds] ) {
return false;
} else {
return true; // No error message specified
}
}
Note that this validator returns "true" when the user's input is incorrect, as in "Yes, it's true,
there was a problem with that input". If you prefer to provide more information when a validator
detects a problem with input, you can specify an error message in the validator that angular will
display when the user hovers over the input widget.
To specify an error message, replace "`return true;`" with an error string, for example:
return "Must be a value between 1 and 5!";
Following is a sample UPS Tracking Number validator: