2017 © Pedro Peláez
 

library brazilian-phone-validator

Validator for Brazilian phone numbers

image

empregoligado/brazilian-phone-validator

Validator for Brazilian phone numbers

  • Wednesday, April 12, 2017
  • by eriksencosta
  • Repository
  • 41 Watchers
  • 16 Stars
  • 2,524 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 1 % Grown

The README.md

BrazilianPhoneValidator

This library provides a validator for Brazilian telephone numbers based on the ranges of telephone numbers from Anatel. It provides validation rules for the main telephone types:, (*1)

  • Cellphones - SMP, Serviço Móvel Pessoal (Personal Mobile Service) in the Anatel specifications
  • Landline phones - STFC, Serviço Telefônico Fixo Comutado (Switched Landline Telephone Service) in the Anatel specifications
  • Push-to-talk phones - SME, Serviço Móvel Especializado (Specialized Mobile Service) in Anatel specifications

Build Status, (*2)

What is Anatel?

According to Wikipedia:, (*3)

"The National Telecommunications Agency (in Portuguese, Agência Nacional de Telecomunicações - Anatel) is a special agency in Brazil created by the general telecommunications act (Law 9472, 16/07/1997) in 1997. The agency is administratively and financially independent, and not hierarchically subordinate to any government agency.", (*4)

Requirements

PHP 5.3 or above., (*5)

Installation

The easiest way to install BrazilianPhoneValidator is through Composer. Just create a composer.json file for your project:, (*6)

{
    "require": {
        "empregoligado/brazilian-phone-validator": "dev-master"
    }
}

And then run these commands:, (*7)

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

Now include the Composer-generated autoload to have access to the library:, (*8)

<?php

require 'vendor/autoload.php';

$validator = new EmpregoLigado\BrazilianPhoneValidator\Validator();

Usage

The EmpregoLigado\BrazilianPhoneValidator\Validator class provides the following high-level public API to validate a Brazilian phone number:, (*9)

  • isValid($phone) (any type of phone number)
  • isValidCellphone($phone)
  • isValidLandline($phone)

And the following lower-level public API to validate a specific Brazilian phone number type:, (*10)

  • isValidSME($phone)
  • isValidSMP($phone)
  • isValidSTFC($phone)

Where $phone is a "numeric" string with the area code and phone number (examples: 1149502480 and 6134111200.), (*11)

Usage example:, (*12)

<?php

$validator = new EmpregoLigado\BrazilianPhoneValidator\Validator();

$phone = '6134111200';

// Checks if it is a valid Brazilian phone number.
if ($validator->isValid($phone)) {
    // success statement
} else {
    // error statement
}

Creating/updating the dataset files

The dataset files available in the data/ directory are created and updated by the bin/dataset-processor.php script. It generates a JSON and a PHP file for each processed dataset file., (*13)

To process the dataset files correctly, you must download the latest "Geral" (general) file, process it and then process all (if any) the additional incremental files which the date is greater than the "Geral" file date., (*14)

$ php bin/dataset-processor.php /path/to/FAIXA_SMP_20130803_0330_GERAL.txt data/

This library ships with the latest possible dataset version. You can download them independently to use for validation or for other purposes., (*15)

Anatel dataset files (SME, SMP and STFC)

License

This library is licensed under the MIT license - see the LICENSE file for details., (*16)

The Versions

12/04 2017

dev-master

9999999-dev http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Lucas Michelini Reis de Oliveira

validator brazil standards

04/02 2016

dev-update-dataset

dev-update-dataset http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Lucas Michelini Reis de Oliveira

validator brazil standards

16/04 2015

v0.0.8

0.0.8.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Lucas Michelini Reis de Oliveira

validator brazil standards

05/11 2014

v0.0.7

0.0.7.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Lucas Michelini Reis de Oliveira

validator brazil standards

19/09 2014

v0.0.6

0.0.6.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

26/03 2014

v0.0.5

0.0.5.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

22/01 2014

v0.0.4

0.0.4.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

22/01 2014

dev-ninth-digit

dev-ninth-digit http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

25/09 2013

v0.0.3

0.0.3.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

30/08 2013

v0.0.2

0.0.2.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards

23/08 2013

v0.0.1

0.0.1.0 http://github.com/EmpregoLigado/BrazilianPhoneValidator

Validator for Brazilian phone numbers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Lucas Michelini Reis de Oliveira

validator brazil standards