Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(\+?1\ ?)?\(?[0-9]{3}\)?\-?\ ?[0-9]{3}\-?\ ?[0-9]{4}$
/
gm

Description

Captures every kind of US format I can think of (e.g +1999-999-999, 999-999-9999, +1(999) 999-9999, etc). Remove first coupling group if you don't want a country code.

Submitted by Kayla B, - 6 months ago