davideme / libphonenumber-for-PHP

PHP version of Google's phone number handling library
125 stars 71 forks source link

Libphonenumber-for-PHP fails to validate phone number #31

Open shafeekb4u opened 8 years ago

shafeekb4u commented 8 years ago

Iam using this API for international phone no validation.It's working fine,but as per the guidence in that github page i have given

"$swissNumberStr = "044 668 18 00";" and $phoneUtil->parse($swissNumberStr, "CH");

as inputs... and when we are calling

$isValid = $phoneUtil->isValidNumber($swissNumberProto);

it should return true..because its a valid one.But for me it's getting false..any help would be much appreciated..

SOURCE : libphonenumber-for-PHP fails to validate phone number

demo.php

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;