I've been looking at Angular docs here: https://docs.angularjs.org/guide/forms#custom-validation
I'm trying to create my own input field validator using a custom directive. I've created a directive which seems identical to the one from the link above, only customized with my own validation function (6-digit password):
app.directive('password', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
ctrl.$validators.password = function (modelValue, viewValue) {
if (/^[0-9]{6}$/.test(viewValue)) {
return true;
}
return false;
};
}
};
});
And when I run it, I get this error:
Error: ctrl.$validators is undefined
What am I missing here?
$validators
only exist since version 1.3. Contrary to your comment the latest stable version is 1.3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With