Reputation: 2066
i have a phone number in following format +923334173333 and now i want to validate this number exactly in the given format and length with php
Upvotes: 1
Views: 444
Reputation: 23255
You can test the length with strlen(), and use ctype_digit() in combination with substr() to check that the substring starting after the '+' consists only of digits.
Upvotes: 0
Reputation: 222090
Fastest way would be
function validatePhoneNumber($n)
{
return strlen($n) == 13 && $n[0] == '+' && ctype_digit(substr($n, 1)) == 13;
}
validatePhoneNumber('+923334173333'); // returns true
Upvotes: 2
Reputation: 2379
You would need the rules for all possible types of phone numbers and their limitation in the whole world. I'm uncertain if such list even exists.
Upvotes: 0