All Projects → EmpregoLigado → BrazilianPhoneValidator

EmpregoLigado / BrazilianPhoneValidator

Licence: MIT license
Validator for Brazilian phones based on the official Anatel datasets

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to BrazilianPhoneValidator

ccsearch-browser-extension
[PROJECT TRANSFERRED] Cross-Browser extension to search, filter and use images in the public domain and under Creative Commons licenses.
Stars: ✭ 115 (+576.47%)
Mutual labels:  discontinued
cccatalog-frontend
[PROJECT TRANSFERRED] CC Search is a search tool for CC-licensed and public domain content across the internet.
Stars: ✭ 160 (+841.18%)
Mutual labels:  discontinued
cccatalog-dataviz
Data visualizations of CC-licensed works across the internet.
Stars: ✭ 19 (+11.76%)
Mutual labels:  discontinued
image-crawler
A polite image crawler that can thumbnail and extract metadata from images at scale
Stars: ✭ 17 (+0%)
Mutual labels:  discontinued
WasteWater
Free library for modelling and simulation of waste water treatment plants.
Stars: ✭ 35 (+105.88%)
Mutual labels:  discontinued
hackfastalgos
A library of various fast algorithms written in Hack
Stars: ✭ 34 (+100%)
Mutual labels:  discontinued
b2g-installer
DEPRECATED - Tools to easily flash b2g on your android phone
Stars: ✭ 27 (+58.82%)
Mutual labels:  discontinued
discord-theme
CSS Theme for Discord. (discontinued)
Stars: ✭ 16 (-5.88%)
Mutual labels:  discontinued

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:

  • 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

What is Anatel?

According to Wikipedia:

"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."

Requirements

PHP 5.3 or above.

Installation

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

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

And then run these commands:

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

Now include the Composer-generated autoload to have access to the library:

<?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:

  • 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:

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

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

Usage example:

<?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.

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.

$ 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.

Anatel dataset files (SME, SMP and STFC)

License

This library is licensed under the MIT license - see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].