用于PHP的libphonenumber无法验证电话号码
我正在使用国际电话没有验证。它工作正常,但按照我在github页面上给出的指南 “$swissNumberStr=“044 668 18 00”;”和$phoneUtil->parse($swissNumberStr,“CH”) 作为输入。。。 当我们打电话的时候 $isValid=$phoneUtil->isValidNumber($swissNumberProto)强> 它应该是真的因为它是有效的但对我来说它是假的任何帮助都将不胜感激 demo.php用于PHP的libphonenumber无法验证电话号码,php,validation,libphonenumber,Php,Validation,Libphonenumber,我正在使用国际电话没有验证。它工作正常,但按照我在github页面上给出的指南 “$swissNumberStr=“044 668 18 00”;”和$phoneUtil->parse($swissNumberStr,“CH”) 作为输入。。。 当我们打电话的时候 $isValid=$phoneUtil->isValidNumber($swissNumberProto) 它应该是真的因为它是有效的但对我来说它是假的任何帮助都将不胜感激 demo.php use com\google\i18n\p
use com\google\i18n\phonenumbers\PhoneNumberUtil;
use com\google\i18n\phonenumbers\PhoneNumberFormat;
use com\google\i18n\phonenumbers\NumberParseException;
require_once 'PhoneNumberUtil.php';
$swissNumberStr = "044 668 18 00";
$phoneUtil = PhoneNumberUtil::getInstance();
try {
$swissNumberProto = $phoneUtil->parseAndKeepRawInput($swissNumberStr, "CH");
echo $phoneUtil->getNumberType($swissNumberProto);
//var_dump($swissNumberProto);
} catch (NumberParseException $e) {
echo $e;
}
$isValid = $phoneUtil->isValidNumber($swissNumberProto);//return true
var_dump($isValid);
// Produces "+41446681800"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::NATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US") . PHP_EOL;
您使用了错误的函数进行分析 使用
phUtil.Parse(Germanumberstr,“CH”)
与parseAndKeepRawInput不同,可能有助于查看真实代码…删除前缀0@fayyazkl它..保持不变..其他行给出了精确的输出。但验证行只显示false。。