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