<?php $regex = "/^(\(?\d{3}\)?)?[- .]?(\d{3})[- .]?(\d{4})$/"; $values = array("1235551234","800.555.1234", "123-555-1234" ); foreach ($values as $value) { $formattedValue = preg_replace($regex, "(\\1) \\2-\\3", $value); echo $formattedValue . "\n"; } ?>