Posted By

chrisvogt on 12/30/12


Tagged

phone number length validate telephone


Versions (?)

Check 10- and 11- digit phone numbers


 / Published in: PHP
 

Return a pure 10-digit phone number if the number given is 10 digits or 11 digits.

  1. function is_phone($phone) {
  2. $phone = preg_replace('/[^\d]+/', '', $phone);
  3. $num_digits = strlen($phone);
  4. if($num_digits == 10 || $num_digits == 11) {
  5. return $phone;
  6. } else {
  7. return FALSE;
  8. }
  9. }

Report this snippet  

You need to login to post a comment.