Regex - Phone numbers or empty space not working - regex

I have this regex for phone numbers in New Zealand:
^\+?[\d\s\(\)]{1,14}$|^((\+?64\s*[\(]?2\d{1}[\)]?|\(?02\d{1}\)?)\s*\d{3}\s*\d{3,5})$
I want to allow an empty string as well so I do what the internet says to do (add ^$| to the front):
As you can see it makes most of the passing numbers fail. It does the same thing when I add brackets to the front.
How do I allow empty strings and also phone numbers using the expression at the top of this question?
Please copy paste this into regexr.com to experiment with possible solutions:
expression:
^\+?[\d\s\(\)]{1,14}$|^((\+?64\s*[\(]?2\d{1}[\)]?|\(?02\d{1}\)?)\s*\d{3}\s*\d{3,5})$
Text:
Positive:
021 755 2375
+79261234567
9261234567
+1234567
89261234567
4035555678
23423
3454
021 2343234
926 3 4
1 416 555 9292
926 1234567
495 1234567
+7 555 1234567
+7(926)1234567
(926) 1234567
469 123 45 67
0800 345345786
09 419 7555
0800 475 4669
202 555 4567
Negative:
027 .343 -454
8 800 600-APPLE
+42 555.123.4567
926.123.4567
64 25 .435 -34323
025 .435 -343
123-4567
123-89-01
+1-(800)-123-4567
8 (926) 1234567
415-555-1234
650-555-2345
(416)555-3456
09-419 7555
364563456345645643565346768

Use grouping:
(?:^$)|(?:^\+?[\d\s\(\)]{1,14}$|^((\+?64\s*[\(]?2\d{1}[\)]?|\(?02\d{1}\)?)\s*\d{3}\s*\d{3,5})$)
Demo

Related

Regex for Australian phone numbers WITH toll-free numbers

There are a number of questions about regex for Australian phone numbers. They cover things like:
0411 123 123
0411123123
+61 411 123 123
+61411123123
(03) 9999 9999
(02)99999999
07 9999 9999
0899999999
The working JS regex for this is below and here https://regex101.com/r/bRbrVZ/1
/^(?:\+?(61))? ?(?:\((?=.*\)))?(0?[2-57-8])\)? ?(\d\d(?:[- ](?=\d{3})|(?!\d\d[- ]?\d[- ]))\d\d[- ]?\d[- ]?\d{3})$/
BUT, I can't work out where to add to this our free call and local call numbers:
13 11 22
131122
1300 111 222
1300111222
1800 111 222
1800111222
And these numbers can't be prefixed with +61
Thanks in advance!
I have come up with this. I feel it's a bit crude, but it works
^(?:\+?(61))? ?(?:\((?=.*\)))?(0?[2-57-8])\)? ?(\d\d(?:[- ](?=\d{3})|(?!\d\d[- ]?\d[- ]))\d\d[- ]?\d[- ]?\d{3})|(13\s?(\d?\s?\d{3}?|\s?\d{2}\s?\d{2})|1[38]00\s?(\d{2}\s?\d{2}\s?\d{2}|\d{3}\s?\d{3}))$
https://regex101.com/r/ay4R67/2/

add number as prefix

I have list of number:
19
20
21
22
23
24
25
26
many more numbers...
I want to add one number to all of then as prefix so thay will all becam etree digit numbers:
219
220
221
222
223
224
225
226
It should go lik this in find section: \S{2,} than what should I put in replace section? 2$1 or what I em not expert.
Find all two digits and capture them (with parentheses).
\b(\d\d)\b
Replace captured groups with an additional 2 in front.
2$1

Regex to match different formats of phone numbers

I have a bunch of numbers which I want to parse.
+79261234567
89261234567
79261234567
9261234567
+7 926 123 45 67
8(926)123-45-67
123-45-67
79261234567
(495)1234567
(495) 123 45 67
89261234567
8-926-123-45-67
8 927 1234 234
8 927 12 12 888
8 927 12 555 12
8 927 123 8 123
What I came with at first is cycle through all the variants like this
(\+[\d]{11}|[\d]{10,11}|\+\d\ [\d]{3}\ [\d]{3}\ [\d]{2}\ [\d]{2}|\d\([\d]{3}\)[\d\-]{9}|[\d\ ]{14,15}|[\d\-]{14,15}|[\d\-]{9}|\(\d\d\d\)[\d\-]{9,10}|\(\d\d\d\)[\d\ ]{9,10}|\(\d\d\d\)[\d\-]{7})
Is there more elegant way to match these numbers?
This regex will match all of the examples and not much extra:
[+]?(\b\d{1,2}[ -]?)?([(]?\d{3}[)]?)((?:[ -]?\d){4,7})(?![ -]?\d)
It can contain between 7 to 12 digits.
Although it would still match with something like this :
+12 (345) 6-7-8 9-0-1
But that should be within acceptable limits.
However, that one could still match part of a longer number.
And to avoid that it would need some negative look-behinds.
(note that there are no look-behinds in javascript regex)
[+]?(?<!\d)(?<!\d[ -])(?:((\d{1,2}[ -]?)?[(]?\d{3}[)]?[ -]?)(\d(?:[ -]?\d){3,6}))(?![ -]?\d)
Here's a regex101 test for that last one.
To have a more elegant solution, you will have to make the pattern more relaxed. One option is to capture 7, 10, or 11 numbers separated by 0 or more delimiters:
\+?(?:[ ()-]*\d){10,11}|(?:[ ()-]*\d){7}
Regex101 Tested

Find numbers using regular expression with egrep in Linux terminal

I want to find all separated words (which means characters between two spaces), that are decimal numbers including plus and minus signs in Linux terminal using egrep.
My solution:
(?<= |\n|\t)[\+\-]?[0-9]+(?= |\n|\t)
Explanation:
(?<= |\n|\t) checks if there is a space or newline or tabulator before decimal number
(?= |\n|\t) checks if there is a space or newline or tabulator after decimal number.
This code works well in program Kiki 0.5.6 where I test implementation, but if I copy it to terminal, it doesn't work. I think that terminal doesn't recognize special parentheses constructions (?= or ?<=). Am I right? How can I apply to terminal?
For example: my text:
1.fasfa
123asfavdsvdas156
1safsavdsvsd1sdva5s31as35d1va
595s6dva2sdvas9
asd9as5dv92s
sd559vs fs5s94 4dfs dfa4s44 459 9dasf 8sdfa 5sfa
napr. uNIveRziTA
sfaf 2262 2226 56565 adss
uNiVerZita
uNIVERZITa
123
123 sadasf 123456 sfafs 134
-1234- -25- -5- 5- --55
-
-55
123 100 999 124 6262 62 6 2 62 62 65 26565 22 62 62652 +665 +0649 ---662 265 959 595 099 199 -059 -0245 -444
--1245 -555-5-55 --555- 555-
+25
-55
+++55 +5 ++5 ++55+665+
samo samo samo samo otec otec skola skola samo lamo samo lamo
re20. (?<=(\t|\n| ))([+-])?[1-9][0-9]*(?= |$|\n)
--- ---
doma doma doma doma doma doma doma doma doma
meno.priezvisko#tuke.sk meno.priezvisko.1#tuke.sk meno.priezvisko#student.tuke.sk meno.priezvisko.2#student.tuke.sk
23:56:59.555
00:00:00.000
23:59:59.999
31/12/2099
00/12/2054
01/01/2000
matches:
459
2262
2226
56565
123
123
123456
134
-55
123
100
999
124
6262
62
6
2
62
65
26565
22
62
62652
+655
+0649
egrep does not support lookaround assertions. However, GNU grep comes with perl compatible regular expressions using the -P switch:
grep -oP '(?<=\s|^)[+-]?[0-9]+(?=\s|$)' input
Note that you can simplify |\n|\t to \s which stands for whitespace character. In order to match numbers that start at the begin of a line and numbers that end at the end of the line I've added ^ and $ as alternatives for \s.

Regular expression to match standard 10 digit phone number

I want to write a regular expression for a standard US type phone number that supports the following formats:
###-###-####
(###) ###-####
### ### ####
###.###.####
where # means any number. So far I came up with the following expressions
^[1-9]\d{2}-\d{3}-\d{4}
^\(\d{3}\)\s\d{3}-\d{4}
^[1-9]\d{2}\s\d{3}\s\d{4}
^[1-9]\d{2}\.\d{3}\.\d{4}
respectively. I am not quite sure if the last one is correct for the dotted check. I also want to know if there is any way I could write a single expression instead of the 4 different ones that cater to the different formats I mentioned. If so, I am not sure how do I do that. And also how do I modify the expression/expressions so that I can also include a condition to support the area code as optional component. Something like
+1 ### ### ####
where +1 is the area code and it is optional.
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
Matches the following
123-456-7890
(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890
If you do not want a match on non-US numbers use
^(\+0?1\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
Update :
As noticed by user Simon Weaver below, if you are also interested in matching on unformatted numbers just make the separator character class optional as [\s.-]?
^(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
https://regex101.com/r/j48BZs/2
There are many variations possible for this problem. Here is a regular expression similar to an answer I previously placed on SO.
^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$
It would match the following examples and much more:
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
800 555 1234x5678
8005551234 x5678
1 800 555-1234
1----800----555-1234
Regardless of the way the phone number is entered, the capture groups can be used to breakdown the phone number so you can process it in your code.
Group1: Country Code (ex: 1 or 86)
Group2: Area Code (ex: 800)
Group3: Exchange (ex: 555)
Group4: Subscriber Number (ex: 1234)
Group5: Extension (ex: 5678)
Here is a breakdown of the expression if you're interested:
^\s* #Line start, match any whitespaces at the beginning if any.
(?:\+?(\d{1,3}))? #GROUP 1: The country code. Optional.
[-. (]* #Allow certain non numeric characters that may appear between the Country Code and the Area Code.
(\d{3}) #GROUP 2: The Area Code. Required.
[-. )]* #Allow certain non numeric characters that may appear between the Area Code and the Exchange number.
(\d{3}) #GROUP 3: The Exchange number. Required.
[-. ]* #Allow certain non numeric characters that may appear between the Exchange number and the Subscriber number.
(\d{4}) #Group 4: The Subscriber Number. Required.
(?: *x(\d+))? #Group 5: The Extension number. Optional.
\s*$ #Match any ending whitespaces if any and the end of string.
To make the Area Code optional, just add a question mark after the (\d{3}) for the area code.
^(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
Matches these phone numbers:
1-718-444-1122
718-444-1122
(718)-444-1122
17184441122
7184441122
718.444.1122
1718.444.1122
1-123-456-7890
1 123-456-7890
1 (123) 456-7890
1 123 456 7890
1.123.456.7890
+91 (123) 456-7890
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
+1 (800) 123-4567
18001234567
1 800 123 4567
+1 800 123-4567
+86 800 123 4567
1-800-123-4567
1 (800) 123-4567
(800)123-4567
(800) 123-4567
(800)1234567
800-123-4567
800.123.4567
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123)123 1231
(123) 123-1231
(123) 123 1231
+99 1234567890
+991234567890
(555) 444-6789
555-444-6789
555.444.6789
555 444 6789
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
(003) 555-1212
(103) 555-1212
(911) 555-1212
18005551234
1 800 555 1234
+86 800-555-1234
1 (800) 555-1234
See regex101.com
Regex pattern to validate a regular 10 digit phone number plus optional international code (1 to 3 digits) and optional extension number (any number of digits):
/(\+\d{1,3}\s?)?((\(\d{3}\)\s?)|(\d{3})(\s|-?))(\d{3}(\s|-?))(\d{4})(\s?(([E|e]xt[:|.|]?)|x|X)(\s?\d+))?/g
Demo: https://www.regextester.com/103299
Valid entries:
/* Full number */
+999 (999) 999-9999 Ext. 99999
/* Regular local phone number (XXX) XXX-XXXX */
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123)123 1231
(123) 123-1231
(123) 123 1231
/* International codes +XXX (XXX) XXX-XXXX */
+99 1234567890
+991234567890
/* Extensions (XXX) XXX-XXXX Ext. XXX... */
1234567890 Ext 1123123
1234567890Ext 1123123
1234567890 Ext1123123
1234567890Ext1123123
1234567890 Ext: 1123123
1234567890Ext: 1123123
1234567890 Ext:1123123
1234567890Ext:1123123
1234567890 Ext. 1123123
1234567890Ext. 1123123
1234567890 Ext.1123123
1234567890Ext.1123123
1234567890 ext 1123123
1234567890ext 1123123
1234567890 ext1123123
1234567890ext1123123
1234567890 ext: 1123123
1234567890ext: 1123123
1234567890 ext:1123123
1234567890ext:1123123
1234567890 X 1123123
1234567890X1123123
1234567890X 1123123
1234567890 X1123123
1234567890 x 1123123
1234567890x1123123
1234567890 x1123123
1234567890x 1123123
Here's a fairly compact one I created.
Search: \+?1?\s*\(?-*\.*(\d{3})\)?\.*-*\s*(\d{3})\.*-*\s*(\d{4})$
Replace: +1 \($1\) $2-$3
Tested against the following use cases.
18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
1--800--123--4567
+1 (800) 123-4567
Adding up an example using above mentioned solutions on jsfiddle.
I have modified the code a bit as per my clients requirement. Hope this also helps someone.
/^\s*(?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *[x/#]{1}(\d+))?\s*$/
See Example Here
Phone number regex that I use:
/^[+]?(\d{1,2})?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/
Covers:
18001234567
1 800 123 4567
+1 800 123-4567
+86 800 123 4567
1-800-123-4567
1 (800) 123-4567
(800)123-4567
(800) 123-4567
(800)1234567
800-123-4567
800.123.4567
try this for Pakistani users .Here's a fairly compact one I created.
((\+92)|0)[.\- ]?[0-9][.\- ]?[0-9][.\- ]?[0-9]
Tested against the following use cases.
+92 -345 -123 -4567
+92 333 123 4567
+92 300 123 4567
+92 321 123 -4567
+92 345 - 540 - 5883
Starting with #Ravi's answer, I also applied some validation rules for the NPA (Area) Code.
In particular:
It should start with a 2 (or higher)
It cannot have "11" as the second and third digits (N11).
There are a couple other restrictions, including reserved blocks (N9X, 37X, 96X) and 555, but I left those out, particularly because the reserved blocks may see future use, and 555 is useful for testing.
This is what I came up with:
^((\+\d{1,2}|1)[\s.-]?)?\(?[2-9](?!11)\d{2}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
Alternately, if you also want to match blank values (if the field isn't required), you can use:
(^((\+\d{1,2}|1)[\s.-]?)?\(?[2-9](?!11)\d{2}\)?[\s.-]?\d{3}[\s.-]?\d{4}$|^$)
My test cases for valid numbers (many from #Francis' answer) are:
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
My invalid test cases include:
(003) 555-1212 // Area code starts with 0
(103) 555-1212 // Area code starts with 1
(911) 555-1212 // Area code ends with 11
180055512345 // Too many digits
1 800 5555 1234 // Prefix code too long
+1 800 555x1234 // Invalid delimiter
+867 800 555 1234 // Country code too long
1-800-555-1234p // Invalid character
1 (800) 555-1234 // Too many spaces
800x555x1234 // Invalid delimiter
86 800 555 1212 // Non-NA country code doesn't have +
My regular expression does not include grouping to extract the digit groups, but it can be modified to include those.
I find this regular expression most useful for me for 10 digit contact number :
^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$
Reference: https://regex101.com/r/QeQewP/1
Explanation:
Perhaps the easiest one compare to several others.
\(?\d+\)?[-.\s]?\d+[-.\s]?\d+
It matches the following:
(555) 444-6789
555-444-6789
555.444.6789
555 444 6789
The expressions for 1, 3 and 4 are quite similar, so you can use:
^([1-9]\d{2})([- .])(\d{3})$2(\d{4})$
Note that, depending on the language and brand of regexes used, you might need to put \2 instead of $2 or such matching might not be supported at all.
I see no good way to combine this with the format 2, apart from the obvious ^(regex for 1,3,4|regex for 2)$ which is ugly, clumsy and makes it hard to get out the parts of the numbers.
As for the area code, you can add (\+\d)? to the beginning to capture a single-digit area code (sorry, I don't know the format of your area codes).
How about this?
^(\+?[01])?[-.\s]?\(?[1-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}
EDIT: I forgot about the () one.
EDIT 2: Got the first 3 digit part wrong.
This code will match a US or Canadian phone number, and will also make sure that it is a valid area code and exchange:
^((\+1)?[\s-]?)?\(?[2-9]\d\d\)?[\s-]?[2-9]\d\d[\s-]?\d\d\d\d
Test on Regex101.com
This is my Regex the worked on US numbers in the FreeCodeCamp phone number challenge:
/^\d{3}(-|\s)\d{3}(-|\s)\d{4}$|^\d{10}$|^1\s\d{3}(-|\s)\d{3}(-|\s)\d{4}$|^(1\s?)?\(\d{3}\)(\s|\-)?\d{3}\-\d{4}$/
Matches:
555-555-5555
(555)555-5555
(555) 555-5555
555 555 5555
5555555555
1 555 555 5555 etc
Above regex is a slight modification of #Francis Gagnon.
Objective : To detect any possible pattern a user can share their US phone number
Version 1:
^\s*(?:\+?(\d{1,3}))?[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d[\W\D\s]*?\d)(?: *x(\d+))?\s*$
Test it over here Codepen: https://codepen.io/kiranbhattarai/pen/NWKMXQO
Explanation of the regex : https://regexr.com/4kt5j
Version 2:
\s*(?:\+?(\d{1,3}))?[\W\D\s]^|()*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d[\W\D\s]*?\d)(?: *x(\d+))?\s*$
What is in it: The test cases can be a part of the string. In version one the test cases should be a start of a line to work.
Codepen: https://codepen.io/kiranbhattarai/pen/GRKGNGG
Explanation of the regex : https://regexr.com/4kt9n
If you can find a pattern that can fail please do comment i will fix it.
Test Cases: Pass
8 0 0 4 4 4 5 55 5
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
800 555 1234x5678
8005551234 x5678
1 800 555-1234
1----800----555-1234
800 (555) 1234
800(555)1234
8 0 0 5 5 5 1 2 3 4
8.0.0.5.5.5.1.2.3.4
8-0-0-5-5-5-1-2-3-4
(8)005551234
(80)05551234
8(00)5551234
8#0#0#5551234
8/0/0/5/5/5/1/2/3/4
8*0*0*5*5*5*1*2*3*4
8:0:0:5:5:5:1:2:3:4
8,0,0,5,5,5,1,2,3,4
800,555,1234
800:555:1234
1-718-444-1122
718-444-1122
(718)-444-1122
17184441122
7184441122
718.444.1122
1718.444.1122
1-123-456-7890
1 123-456-7890
1 (123) 456-7890
1 123 456 7890
1.123.456.7890
+91 (123) 456-7890
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
+1 (800) 123-4567
18001234567
1 800 123 4567
+1 800 123-4567
+86 800 123 4567
1-800-123-4567
1 (800) 123-4567
(800)123-4567
(800) 123-4567
(800)1234567
800-123-4567
800.123.4567
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123) 123-1231
(123) 123 1231
+99 1234567890
+991234567890
(555) 444-6789
555-444-6789
555.444.6789
555 444 6789
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
(003) 555-1212
(103) 555-1212
(911) 555-1212
18005551234
1 800 555 1234
+86 800-555-1234
1 (800) 555-1234
I'm just throwing this answer in there since it solves a problem of mine, it's based off of #stormy's answer, but includes 3 digit country codes and more importantly can be used anywhere in a string, but won't match is it's not preceded by a space/start of the string and ending with a word boundary. This is useful so that it won't match random numbers in the middle of a URL or something
((?:\s|^)(?:\+\d{1,3}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4})(?:\b)
Here's a regex that matches North American numbers as well as international numbers such as for middle east.
^((\+|0{0,2})([0-9]){1,3})?[-.●\s]?\(?([0-9]{2,3})\)?[-.●\s]?([0-9]{3})[-.●\s]?([0-9]{4})$
I know this doesn't answer OP's question directly but if you are asking the same question as OP there is a good chance your are looking for a way to validate and store a phone number in either state or a database. Instead of trying to detect every possible combination of character that could be a phone number you might find it easier to break this task into multiple steps.
strip out all none numbers
strip out leading 1s
make sure the number is at most 10 digits
Javascript pseudo example assuming "phone" is user input stored as a string:
phone.replace(/\D/g, "")
phone.replace(/^1+/g, "")
phone.slice(0, 10)
phone.length === 10 ? "do something" : "don't do something"
Code above will need to be tweaked for your purposes and is left as simple as possible for none javascript readers.
For presentation purposes you can always layer dashes and leading 1s back in later but for storage you should probable only keep the actual numbers. This approach also has the added advantage of leaving you with some easy to digest regular expressions.
^(\+1)?\s?(\([1-9]\d{2}\)|[1-9]\d{2})(-|\s|.)\d{3}(-|\s|.)\d{4}
This is a more comprehensive version that will match as much as I can think of as well as give you group matching for country, region, first, and last.
(?<number>(\+?(?<country>(\d{1,3}))(\s|-|\.)?)?(\(?(?<region>(\d{3}))\)?(\s|-|\.)?)((?<first>(\d{3}))(\s|-|\.)?)((?<last>(\d{4}))))
what about multiple numbers with "+" and seperate them with ";" "," "-" or " " characters?
I ended up with
const regexBase = '(?:\\+?(\\d{1,3}))?[-. (]*(\\d{3})?[-. )]*(\\d{3})[-. ]*(\\d{4,5})(?: *x(\\d+))?';
const phoneRegex = new RegExp('\\s*' + regexBase + '\\s*', 'g');
this was to allow for things like dutch numbers, for example
+358 300 20200