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

Hello @Amit Gujarathi 

 

I tried your expression and I was able to submit with the no space between the +1and the area code

@Amit Gujarathi I tested your expression. I'm still able to submit with no space between the +1 and the area code.

DanielCordick
Mega Patron
Mega Patron

this might work


^1\s\d{3}-\d{3}-\d{4}$

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

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

 

or 

 

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