验证php中的任何电话号码[重复]

This question already has an answer here:

Please I need help to validate phone numbers in various formats

Valid formats:

+111 1 11111111
+11 1111111
1111111
(+111) (11) 1111111

Etc, the format is:

  • You can take a "+" sign only at the beginning and once. Can lead an
  • open and closed parenthesis only the beginning. You can not have more
  • than 15 numbers in total. Can not be less than 8 numbers in total.

Have This:

if(strlen($buff) < 8)
    return false;

$buff = trim(preg_replace('/\s+/', ' ', $buff));

if(preg_match('/^\(\d\) \d \d$/', $buff))
    return $buff;

return false;

Thanks.

</div>

Smartphone tactics:

  1. remove all non-numeric characters but not the +
  2. replace first sign by 00 if it is a +
  3. replace leading 000 by 00
  4. match possible country code
  5. check length between x and y

You don't even need regex for that.