Skip to content

Instantly share code, notes, and snippets.

View Bluekev22's full-sized avatar

Kevin Shank Bluekev22

View GitHub Profile
@Bluekev22
Bluekev22 / readme.md
Last active September 21, 2021 00:41
Regex Tutorial: Matching a phone number

Regex Tutorial: Matching a phone number

In this tutorial we will be taking a dive into Regex. Regex, or regular expressions, are patterns that are used to search for character combinations in strings. They are used by string-searching algorithms and for matching input validation.

Summary

Today we are going to be taking a look how to implement a regex to verify that a phone number is valid:

/(?:(\+1)[ -]?)?\(?(\d{3})\)?[ -]?(\d{3})[ -]?(\d{4})/