What is the regex pattern for: +1 123-123-1234
Current I am using /^\\(?(\\d{3})\\)?[-\\. ]?(\\d{3})[-\\. ]?(\\d{4})$/
/^\\(?(\\d{3})\\)?[-\\. ]?(\\d{3})[-\\. ]?(\\d{4})$/
/^\\(?(\\d{3})\\)?[-\\. ]?(\\d{3})[-\\. ]?(\\d{4})$/
which can validate 123-123-1234 but I have +1 followed space. So how to update the above pattern for that?
Searched on many sites, but couldn't find any.
Thanks in advance.
Here you go:
\\+1([- ])?\\d{3}-\\d{3}-\\d{4}
I made it so that the +1 can be followed by either a space or a dash, optionally.
Edit: here it is with the first 3 digits in optional brackets aswell
\\+1([- ])?\\(?\\d{3}\\)?-\\d{3}-\\d{4}
So, you could have +1 (123)-123-1234
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.