Check 10- and 11- digit phone numbers


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.