Javascript Regex- Phone Number
i'm trying to find an expression that matches a phone number in the format of (0[2,3,6,7,8,or 9]) XXXXXXXX where X is a digit, the space must be matched and so must the parenthese
Solution 1:
Just remove the \b on either end, and it should work
/\(0[236789]\)\s(\d){8}/g
This will match multiple phone numbers, not sure if that is what you want. If you want to make sure the entire string from start to finish is the full phone number, you can do this
/^\(0[236789]\)\s(\d){8}$/
This will match (02) 12345678, and won't work if there are any characters around the string.
Solution 2:
Well, this is the best I can come up with.
/^[+]?(1\-|1\s|1|\d{3}\-|\d{3}\s|\d{2}\-|\d{2}\s|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})
(\-|\s)?(\d{4})$/g
This should support all combinations like
- (541) 754-3010
- +1-541-754-3010
- 1-541-754-3010
- 001-541-754-3010
- 191 541 754 3010
- +91 541 754 3010
and so on.
Post a Comment for "Javascript Regex- Phone Number"