Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

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

@shafeekb4u

Description

@shafeekb4u

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions