Skip to content

Instantly share code, notes, and snippets.

@Jaballadares
Last active February 14, 2018 23:12
Show Gist options
  • Save Jaballadares/06cb1aafccf345cba466f4919888e9f3 to your computer and use it in GitHub Desktop.
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
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-\.]?
@M-Shahbaz
Copy link

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment