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
doesn't exist yet. – Deepdyed