Web Worm
Web Worm

Reputation: 2066

how can i verify phone number with php

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

Answers (3)

greg0ire
greg0ire

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

Dogbert
Dogbert

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

azatoth
azatoth

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

Related Questions