简体   繁体   中英

Phone number validation which contains +** ***-***-**** (Plus following with Two digit country code with 10 digit mobile number)

I am working on a functionality that has a form which contains a mobile number field. The requirement is to allow the following format for the mobile number field:

+** ***-***-**** 

(Plus following with Two digit country code with 10 digit mobile number) I tried with the below regular expression but wasn't able to produce required result.

ng-pattern="/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"

Can anyone guide me with this?

Try this.

 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"); 

If you want to accept spaces or dots in between like +91 333 333 4444 then you can change ?[-] to ?[-. ]

使用此正则表达式: ng-pattern="/^\\+[0-9]{5}-[0-9]{3}-[0-9]{4}$/"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM