The Form Validation class in CodeIgniter does a lot of fantastic things. Validating phone numbers isn’t one of them. Here is a script I’ve paraphrased to take in almost any format of U.S. phone number and use regular expressions to return it like this: (555) 555-1212.
function _validate_phone_number($value) { $value = trim($value); $match = '/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/'; $replace = '/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/'; $return = '($1) $2-$3'; if (preg_match($match, $value)) { return preg_replace($replace, $return, $value); } else { $this->form_validation->set_message('_validate_phone_number', 'Invalid Phone.'); return false; } }

