Here's my Codeigniter function:
function edit_phone($phone)
{
if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $phone))
{
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1-$2-$3", $phone);
}
else
{
$this->CI->validation->set_message('phone', "This must be a 10-digit USA phone number.");
return FALSE;
}
}
This validates/checks the input alright, but doesn't reformat it in the db.
Validation is great! But why isn't this returning a standard phone number?!