angular.js form validation directive

علی ذوالفقار
1399/06/22 15:37:53 (832)
// add a custom directive to validate nin -> nin_validate
app.directive('ninValidate', function() {
    return {      
      require: 'ngModel', // $validators does not work if ngModel not set       
      link: function(scope, elm, attrs, ctrl) {
        //   console.log(ctrl.$validators)
        ctrl.$validators.ninValidate = function(modelValue, viewValue) { // add a validator to control.$validators (return true/false)
            return validate_nin(viewValue) ; // use validate_nin function as validator logic ;)
        };
      } 
    };
});
Back