[英]jQuery Validation Add Method Regex Number with Parentheses
I'm using jquery validate plugin
with a input field which ask to put into it a phone number and I want to add a validator method with a regex that'll valid any numbers starting with " 9 or 09 or +639 or 639 or (+63) or (+63) 9
" and 9 digit after it 我正在使用带有输入字段的
jquery validate plugin
,要求输入电话号码,并且我想添加带有正则表达式的验证器方法,该方法将对以“ 9 or 09 or +639 or 639 or (+63) or (+63) 9
英寸及其后的9位数字
jQuery.validator.addMethod("phoneno", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
//phone_number.match(/^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/);
phone_number.match(/^(9|09|\+639|639|\((\+63)\) 9)\d{9}$/);
}, "<br />Please specify a valid phone number");
This code works and can valid any number started with +63
, 9
, 09
, 63
except when it start with (+63)
or (+63) 9
As an example, it valid +639123456789 639123456789 9123456789
but not with Parentheses 此代码的工作,并能有效启动与任意数量的
+63
, 9
, 09
, 63
,除了当它与启动(+63)
或(+63) 9
作为一个例子,它有效+639123456789 639123456789 9123456789
但不使用括号
I think that there is a mistake in the match regex 我认为比赛正则表达式有误
^(9|09|\\+?639|\\(\\+63\\)\\s?9?)\\d{9}$
This validates : 这验证:
+639123456789
9123456789
(+63)9123456789
(+63) 9123456789
(+63)123456789
(+63) 123456789
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.