Created Regex Phone number expression for US +1 XXX-XXX-XXXX

KB30
Tera Expert

Hello I'm working on creating a regular expression for a US phone number. The format needs to be +1 XXX-XXX-XXXX.

 

I found this post below which provided a Regex expression of ^\(?([0-9]{3})\)?[-]([0-9]{3})[-]([0-9]{4})$ but I'm having issues wit the leading 1.

https://www.servicenow.com/community/developer-forum/help-on-regex-for-phone-number-format-xxx-xxx-x...

 

Does anyone have any tips or assistance on how to complete this? This isn't my strong suit and my first time working on Regex expression so all help would be great!!

2 ACCEPTED SOLUTIONS

@DanielCordick I tried but I can only submit +1. I can not submit a number

View solution in original post

^\+1\s\d{3}[-]\d{3}[-]\d{4}$

 

or 

 

^\+1\s?\(?([0-9]{3})\)?[-]([0-9]{3})[-]([0-9]{4})$

View solution in original post

15 REPLIES 15

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Try using below regex

/^(\+1)?[-]?([0-9]{3})\)?[-]?([0-9]{3})[-]?([0-9]{4})$/

I received this error

Screenshot 2023-11-27 at 12.58.26 PM.png

 

Please remove the / from start and the end of the regex.

Can you update to remove the hyphen between the 1 and the area code?