2017 © Pedro Peláez
 

library ngr-phone-validator

A PHP Libary to validate a nigerian phone number based on availabe public data

image

dammynex/ngr-phone-validator

A PHP Libary to validate a nigerian phone number based on availabe public data

  • Thursday, July 12, 2018
  • by dammynex
  • Repository
  • 1 Watchers
  • 5 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ngr-phone-validator

A PHP Libary to validate a nigerian phone number based on availabe public data., (*1)

It utilizes some very common data to check if a Nigerian phone number is valid., (*2)

It's very easy to setup and use., (*3)

Using composer, (*4)

composer require dammynex/ngr-phone-validator

Manually Download the zip package and require it, (*5)

require_once 'path/to/dir/vendor/autoload.php';

Validating a phone number without exceptions, (*6)

use Brainex\Tools\PhoneValidator;

$phone = (new PhoneValidator())
                //Phone number to validate
                ->setPhoneNumber('+2349061668519')
                //We do not want exceptions
                ->setThrowExceptions(false)
                //Do validation
                ->validate();

if($phone->isValid()) {
    echo 'The phone number is valid';
}

Validating a phone number using exceptions, (*7)

use Brainex\Tools\PhoneValidator;
use Brainex\Exceptions\InvalidPhoneException;

try {
    $phone = (new PhoneValidator())
                ->setPhoneNumber('+2349061668519')
                ->validate();
} catch(InvalidPhoneException $e) {
    echo 'Invalid phone: ' . $e->getMessage();
}

When PhoneValidator::isValid() returns true, Other methods can be utilized., (*8)

Method Description
__toString() Returns the phone number
getInternationalFormat() Returns the international format of the specified phone number (eg. +2349061668519)
getInternationalFormatWithoutPlusPrefix() Returns the international format with the plus sign (eg. 2349061668519)
getLength() Returns the length of the phone number
getLocalFormat() Returns the local format of specified phone number (eg. 09061668519)
getNetwork() Returns the phone number's network
getPhoneNumber() Returns the raw (unedited) specified phone number
getThrowExceptions() Returns whether validator is assigned to throw exceptions
isOfLength(int $length) Returns whether length of phone number matches a valid phone number length from the Brainex\Tools\PhoneLengthParser class
isNetwork(string $network) Returns whether the phone number's network matches the specified $network. $network should be one from Brainex\Tools\PhoneNetworkParser
isValid() Returns whether phone number is valid
isValidLength() Return whether phone's length is parsed and valid
setPhoneNumber(string $phone) Assign phone number to validator
setThrowExceptions() Assign whether exceptions should be thrown
toJson() Return phone number's data in json string
validate() Initialize validation for the phone number
  • [x] Supports Major Networks

Todo: Support other networks - [ ] Smile - [ ] Ntel - [ ] Spectranet, (*9)

Feel free to contribute!!!, (*10)

The Versions

12/07 2018

dev-master

9999999-dev

A PHP Libary to validate a nigerian phone number based on availabe public data

  Sources   Download

Apache-2.0

The Development Requires

phone number nigeria phone validation nigeria phone nigeria validate phone

23/06 2018

0.1.2

0.1.2.0

A PHP Libary to validate a nigerian phone number based on availabe public data

  Sources   Download

Apache-2.0

The Development Requires

phone number nigeria phone validation nigeria phone nigeria validate phone