How to add custom validation to an AngularJS form?

后端 未结 12 1663
既然无缘
既然无缘 2020-11-22 10:07

I have a form with input fields and validation setup by adding the required attributes and such. But for some fields I need to do some extra validation. How wou

12条回答
  •  借酒劲吻你
    2020-11-22 10:43

    Angular-UI's project includes a ui-validate directive, which will probably help you with this. It let's you specify a function to call to do the validation.

    Have a look at the demo page: http://angular-ui.github.com/, search down to the Validate heading.

    From the demo page:

    
    This e-mail is black-listed!
    

    then in your controller:

    function ValidateCtrl($scope) {
      $scope.blackList = ['bad@domain.com','verybad@domain.com'];
      $scope.notBlackListed = function(value) {
        return $scope.blackList.indexOf(value) === -1;
      };
    }
    

提交回复
热议问题