Regular expression for phone number

Posted by Manimaddu under ASP.NET on 8/11/2014 | Points: 10 | Views : 2014 | Status : [Member] | Replies : 4
Hi All...

I need regular Expression it satisfies the below conditions.

1.Number format must be 123-456-7890
2.When 3 numbers are pressed the hyphen symbol added automatically.
3.It allows only 10 digits.
4.When i clear the number total number must be deleted(includes hyphen).


Thanks in advance.

Thanks & Regards,
Mani Kumar



Responses

Posted by: kgovindarao523-21772 on: 8/12/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
you can achieve this using jquery input mask.
use below cdn path along with jquery plugin.

https://cloud.github.com/downloads/digitalBush/jquery.maskedinput/jquery.maskedinput-1.3.min.js
then apply mask like below.

$("#phone").mask("999-999-99999");


Thank you,
Govind

Manimaddu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ishan7 on: 12/7/2020 [Member] Starter | Points: 25

Up
0
Down
Try This one
^\(?[\d]{3}\)?[\s-]?[\d]{3}[\s-]?[\d]{4}$

Manimaddu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ishan7 on: 12/7/2020 [Member] Starter | Points: 25

Up
0
Down
Try this:

^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

Manimaddu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response