SimpleChurchCRM

Normailze phone numbers using regex in PHP

Recently, it became necessary to normalize phone numbers for my work on SimpleChurchCRM. In order to normalize something, we must first understand it and analyze it.

The following regular expression will match phone numbers and their parts.

([(]?(?P<area>\d{3})[)]?)?(?: ?-?)?(?P<three>\d{3})(?: ?-?)?(?P<four>\d{4})( (x|(ext\.? ))(?P<ext>\d+))?

Note that this requires PHP > 5.2.2 I think.