- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 09:39 AM
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.
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!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:11 PM - edited 12-01-2023 03:13 PM
^\+1\s\d{3}[-]\d{3}[-]\d{4}$
or
^\+1\s?\(?([0-9]{3})\)?[-]([0-9]{3})[-]([0-9]{4})$

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 09:55 AM
Hi,
Try using below regex
/^(\+1)?[-]?([0-9]{3})\)?[-]?([0-9]{3})[-]?([0-9]{4})$/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 10:00 AM
I received this error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 10:01 AM
Please remove the / from start and the end of the regex.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 10:04 AM
Can you update to remove the hyphen between the 1 and the area code?