Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
1?\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})
/

Description

Format phone numbers to look nice!

E.g. 12345678900 --> +1(234)-567-8900 Matches with most ways numbers are stored 1.234.567.8900 1 234 567 8900 Mix and match

Submitted by Mendel Groner - 3 years ago