简体   繁体   中英

How do i validate all countries phone number with php

有没有办法用php验证所有国家的电话号码

you can implement this by using preg_match, i dont think any automatic validation exist

By using a database for storing formats and then checking those with entered phonenumber

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

eg.,

<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}
?>

see this http://php.net/manual/en/function.preg-match.php

Take the information about country phone number starting codes from:
http://www.international-dialing-codes.net/
insert into database, create array, make while cycle where it will get information from DB, then create foreach.. something like that..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM