Using some regular expressions we can easily convert this:
8005551212
Into this:
800.555.1212
In [PHP] we can use this function:
function format_phone($phone)
{
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1.$2.$3", $phone);
}
Not terribly complicated. We can even go in reverse and remove the dots as I’ll demonstrate below. Despite the ease of going from a formatted string to a string of digits and back again, we often run into forms that aren’t usable.


