2017 © Pedro Peláez
 

library mobile-numbers

An international mobile number validator

image

juanparati/mobile-numbers

An international mobile number validator

  • Friday, February 23, 2018
  • by juanparati
  • Repository
  • 1 Watchers
  • 0 Stars
  • 273 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 17 % Grown

The README.md

Build Status, (*1)

MobileNumbers

What is it?

A library that validate and parse mobile phone numbers., (*2)

Right now only phone numbers from the following countries are validated:, (*3)

Country Code
Germany DE
Denmark DK
Spain ES
Finland FI
France FR
Italy IT
Norway NO
Poland PL
Sweden SE
South Africa ZA

Feel free to fork this project and add new countries., (*4)

Installation

composer require juanparati/mobile-numbers

How it works

Validate a phone number:, (*5)

    Validator::country('ES')->isValid('651365485');

It is possible to validate phone numbers that contains the international country code:, (*6)

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

The library provides helper that convert different phone number formats to E.164:, (*7)

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

    $e164_number = $validator->helper->convertToE164($mobile_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($mobile_number);   // Convert number to "+46737322066"
    echo $validator->isValid($e164_number) ? 'Valid!' : 'Not Valid!');

It is also possible to add a valid country code to number without country code:, (*8)

    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)

or stripe the country code, (*9)

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

Other methods:, (*10)

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

Definitions list

Using the helper method "getAllDefinitions" it will obtain the information about the all the codes used in all the definitions:, (*11)

    $definitions = Helper::getAllDefinitions();

The definitions include country prefix code, country code and country flag information., (*12)

Identify phone numbers

Using the helper method "identifyNumber" is possible the identify the country which belongs the phone number. The phone number should contains the international prefix., (*13)

Example:, (*14)

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

Add your country definition

  1. Fork this project
  2. Add a new definition into ./src/Definitions
  3. Add a new unit test into ./tests/Definitions

Backers and contributors

The Versions

23/02 2018

dev-master

9999999-dev

An international mobile number validator

  Sources   Download

GPL GPL-3.0-or-later

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago

23/02 2018

0.9.4

0.9.4.0

An international mobile number validator

  Sources   Download

GPL

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago

31/01 2018

0.9.3

0.9.3.0

An international mobile number validator

  Sources   Download

GPL

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago

13/11 2017

0.9.2

0.9.2.0

An international mobile number validator

  Sources   Download

GPL

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago

09/11 2017

0.9.1

0.9.1.0

An international mobile number validator

  Sources   Download

GPL

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago

09/11 2017

0.9

0.9.0.0

An international mobile number validator

  Sources   Download

GPL

The Requires

  • php >=7.0

 

The Development Requires

by Juan Lago