Skip to content

Instantly share code, notes, and snippets.

View nosremetnarg's full-sized avatar
💀

Grant Emerson nosremetnarg

💀
View GitHub Profile
@nosremetnarg
nosremetnarg / regextTutorial.md
Last active September 26, 2020 22:49
REGEX Tutorial - Validating Phone Numbers

REGEX Tutorial - Phone Number Validation

This regex tutorial will explain how to validate phone numbers. Applying this aspect of regex to forms is a great way to make sure users are giving you correct data.

\(?(\d{3})[-.)]\-?\.?\d{3}[-.]\d{4}

Summary

The above REGEX code allows the developer to find any American phone number as well as obscure the phone number to keep the user data private using Quantifiers, Character Classes, Bracket Expressions, Groups, and Lazy/Greedy Matching.