- preg_match: documentation ( source)
<?php
$values = '222-333-4545';
if (strlen($values) > 0 && !preg_match('/^[0-9]{1,3}-[0-9]{3}-[0-9]{3,4}-[0-9]{3,4}$/', $values)) {
$err_msg[4] = ('Phone number must be in format xxx-xxx-nnnn-nnnn.');
echo $err_msg[4];
}