如何在仅数字验证中允许空格,最少8位数?
允许空格时,电话号码更容易输入.例如0400 123 456,9699 1234.
允许空格时,电话号码更容易输入.例如0400 123 456,9699 1234.
到目前为止,这是我的代码,我只有最低8位数的验证工作:
jQuery.validator.addMethod( "phone",function(phone_number,element) { return this.optional(element) || /^\d{8}$/.test(phone_number); },"Please enter numbers only" );
解决方法
在验证之前删除空格:
return this.optional(element) || /^\d{8,}$/.test(phone_number.replace(/\s/g,''));
这样你就可以保留空间