Clean 10 Digit Phone Number


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private function _remove_non_numeric($string) {
  2. return preg_replace('/\D/', '', $string);
  3. }
  4.  
  5. private function _clean_phone_number($phone_number)
  6. {
  7. $CI = &get_instance();
  8.  
  9. $phone_number = $CI->_remove_non_numeric($phone_number);
  10.  
  11. if((strlen($phone_number) >= 11) AND ($phone_number[0] == '1'))
  12. {
  13. $string = substr($phone_number, 1);
  14. }
  15.  
  16. return $phone_number;
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.