PHP code example of juanparati / mobile-numbers

1. Go to this page and download the library: Download juanparati/mobile-numbers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juanparati / mobile-numbers example snippets


Validator::country('ES')->isValid('651365485');
        
Validator::country('DK')->isValid('+4560514180');
Validator::country('SE')->isValid('0046767164315');

$validator = Validator::country('PL');
$raw_number = '(669) 823-955';

$e164_number = $validator->helper->convertToE164($raw_number);   // Convert number to "669823955"
echo ($validator->isValid($e164_number) ? 'Valid!' : 'Not Valid!');


$validator = Validator::country('SE');
$raw_number = '(+46) 7 37322 0-66';

$e164_number = $validator->helper->convertToE164($raw_number);   // Convert number to "+46737322066"
echo ($validator->isValid($e164_number) ? 'Valid!' : 'Not Valid!');

Validator::country('SE')->addCountryCode('0737321066');    // +46737321066
Validator::country('DK')->addCountryCode('60515290');      // +4560515290

Validator::country('DK')->addCountryCode('+4560515290');   // +4560515290  (Country code is not added again)
Validator::country('DK')->addCountryCode('004560515290');  // 004560515290 (Country code is not added again)

Validator::country('SE')->stripCountryCode('0046737321066');   // 0737321066
Validator::country('FI')->stripCountryCode('00358411234567');  // 0411234567
Validator::country('ES')->stripCountryCode('+34670862595');    // 670862595

Validator::country('ES')->helper->hasCountryCode('0030670862595'); // True
Validator::country('ES')->hasValidCountryCode('0030670862595');  // False

$definitions = Helper::getAllDefinitions();

Helper::identifyNumber('+4560514180');  // Returns DK