Reputation: 289
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?
Upvotes: 0
Views: 738
Reputation: 531
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 ?[-. ]
Upvotes: 1
Reputation: 1
Use this regex: ng-pattern="/^\+[0-9]{5}-[0-9]{3}-[0-9]{4}$/"
Upvotes: 0