validate natural input number with ngpattern

前端 未结 3 979
悲&欢浪女
悲&欢浪女 2020-12-01 07:22

I use ng-pattern=\"/0-9/\" to set price_field do not accept decimal number. But when I input natural number (from 0 to 9999999),

3条回答
  •  囚心锁ツ
    2020-12-01 07:50

    
    
    Phone is required.
    

    the following code will help for phone number validation and the respected directive is

    app.directive('validatePhone', function() {
    var PHONE_REGEXP = /^[789]\d{9}$/;
      return {
        link: function(scope, elm) {
          elm.on("keyup",function(){
                var isMatchRegex = PHONE_REGEXP.test(elm.val());
                if( isMatchRegex&& elm.hasClass('warning') || elm.val() == ''){
                  elm.removeClass('warning');
                }else if(isMatchRegex == false && !elm.hasClass('warning')){
                  elm.addClass('warning');
                }
          });
        }
      }
    });
    

提交回复
热议问题