How to apply Multiple ng-pattern with one input control

后端 未结 5 595
甜味超标
甜味超标 2021-01-01 05:30

I am trying to Validate Postal code and Phone Number in Text box using Angularjs. But it\'s not working

 

        
5条回答
  •  猫巷女王i
    2021-01-01 05:33

    See this answer: Angularjs dynamic ng-pattern validation

    You can add a function from scope that returns a true or false based on the validation test. Here is some code below to check out. See the answer for additional information:

    Controller:

    $scope.postalCodeValidation = (function() {
        var regexp = /^\(?(\d{3})\)?[ .-]?(\d{3})[ .-]?(\d{4})$/;
        return {
            test: function(value) {
                return regexp.test(value);
            }
        };
    })();
    

    HTML:

    
    

提交回复
热议问题