I\'m an angular newbie, and I\'m stumbling over something in how angular\'s form validation directives work.
I know that I can fairly easily add directives to in
You may take a look at https://github.com/nelsonomuto/angular-ui-form-validation
This provides a directive that is preconfigured with an api that exposes the scope and its models to your validator function.
Here is a plunker with the your specific use case: http://plnkr.co/edit/S0rBlS?p=preview
The syntax for the directives validators is as shown in the below example :
{
errorMessage: 'Cannot contain the number one',
validator: function (errorMessageElement, val, attr, element, model, modelCtrl){
/**
* The model and modelCtrl(scope) are exposed in the validator function
* */
return /1/.test(val) !== true;
}
}