Last active
February 14, 2018 23:12
-
-
Save Jaballadares/06cb1aafccf345cba466f4919888e9f3 to your computer and use it in GitHub Desktop.
Javascript Regex to Find Different Formats of Phone Numbers in String of Text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option 1: (?=.*?\d{3}( |-|.)?\d{4})((?:\+?(?:1)(?:\1|\s*?))?(?:(?:\d{3}\s*?)|(?:\((?:\d{3})\)\s*?))\1?(?:\d{3})\1?(?:\d{4})(?:\s*?(?:#|(?:ext\.?))(?:\d{1,5}))?)\b | |
Option 2 (maybe better): \+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9} | |
Option 3: (?:\+?(?<COUNTRY_CODE>\d{1})?-?\(?(?<AREA_CODE>\d{3})\)?[\s-\.]?)?(?<PART1>\d{3})[\s-\.]?(?<PART2>\d{4})[\s-\.]? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For format: +00 00 00 000 000
\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}