我如何用PHP验证所有国家的电话号码

时间:2012-04-24 07:12:30

标签: php

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

2 个答案:

答案 0 :(得分:1)

你可以使用preg_match实现这一点,我认为不存在任何自动验证

使用数据库存储格式,然后检查输入的语音

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

例如,

<?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.";
}
?>

看到这个 http://php.net/manual/en/function.preg-match.php

答案 1 :(得分:0)

从以下位置获取有关国家/地区电话号码起始码的信息:
 http://www.international-dialing-codes.net/
插入数据库,创建数组,make while循环,从DB获取信息, 然后创造foreach .. 类似的东西..