有没有办法用php验证所有国家的电话号码
您可以使用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
从以下位置获取有关国家/地区电话号码起始代码的信息:
http://www.international-dialing-codes.net/
插入数据库,创建数组,在循环时从数据库获取信息,然后创建foreach..类似的东西..