I watched Angular docs here: https://docs.angularjs.org/guide/forms#custom-validation
I am trying to create my own input validator using a special directive. I created a directive that seems identical to the one above, only with my own verification 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?
angularjs validation angularjs-ng-model angular-ngmodel
morgoth84
source share