![](/img/trans.png)
[英]Validation for 10 digit mobile number and Showing Color On Input If Invalid
[英]Phone number validation which contains +** ***-***-**** (Plus following with Two digit country code with 10 digit mobile number)
我正在使用具有包含手机号码字段的表单的功能。 要求是手机号码字段采用以下格式:
+** ***-***-****
(再加上两位数字的国家代码和10位的手机号码)我尝试使用以下正则表达式,但无法产生所需的结果。
ng-pattern="/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"
有人可以指导我吗?
尝试这个。
function phonenumber(inputtxt) { var phoneno = /^\\+[0-9]{2}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/; if(inputtxt.match(phoneno)) { //return true; alert("true"); } else { //alert("message"); //return false; alert("false"); } } phonenumber("+91 111 111 1111"); phonenumber("+11-223-333-4444"); phonenumber("984656462464");
如果您想像+91 333 333 4444之间接受空格或点,则可以将?[-]更改为?[-。 ]
使用此正则表达式: ng-pattern="/^\\+[0-9]{5}-[0-9]{3}-[0-9]{4}$/"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.