2017 © Pedro Peláez
 

library laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

image

ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  • Monday, May 21, 2018
  • by ellisio
  • Repository
  • 0 Watchers
  • 2 Stars
  • 4,172 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 19 Versions
  • 17 % Grown

The README.md

Laravel Phone

Latest Stable Version License Total Downloads Build Status , (*1)

- Introduction - Installation - Configuration - Usage - Phone validation - Country validation - Formatting phone numbers - Creating phone number objects - Handling invalid numbers - Support, (*2)

Introduction

A phone validator for Laravel 6+ using the free Twilio Lookup API., (*3)

This package gives developers the ability to validate phone numbers and format phone numbers. All data will be pulled from the Twilio Lookup API., (*4)

Validation can be configured to check if the number is valid, or if it is valid within a given list of ISO-3166-1 Alpha 2 country codes., (*5)

Installation

Install via composer:, (*6)

composer require ellisio/laravel-phone

Add your Twilio credentials to your .env file. If you don't have a Twilio account you can register one here for free., (*7)

TWILIO_ACCOUNT_SID=xxxxxxxx
TWILIO_AUTH_TOKEN=xxxxxxxx

Configuration

If you want to customize the configuration for this package, you can publish the config file to /config/phone.php by running the following command:, (*8)

php artisan vendor:publish --provider=EllisIO/Phone/PhoneServiceProvider --tag=laravel-phone-config

If you want to customize the output of the validation messages, you can publish the translations file to /lang/vendor/laravel-phone by running the following command:, (*9)

php artisan vendor:publish --provider=EllisIO/Phone/PhoneServiceProvider --tag=laravel-phone-translations

Usage

Phone validation

If you need to verify that the given number is valid and that is all, use the phone rule., (*10)

return [
    'phone' => 'required|phone',
];

Country validation

If you need to validate that the given number is valid in a list of countries, use the phone_country:US,CA rule. You can list as many ISO-3166-1 Alpha 2 as you wish delimited by a comma., (*11)

return [
    'phone' => 'required|phone_country:US,CA',
];

Formatting phone numbers

If you want to format the phone number using INTERNATIONAL_FORMAT use the following code:, (*12)

Phone::formatNumber('5551234567');

Creating phone number objects

This library includes the ability to generate a Phone object. This object contains the following details about a number:, (*13)

  • countryCode: ISO-3166 alpha 2 country code.
  • number: E.164 number.
  • formattedNumber: National formatted number.
$phone = Phone::getPhone('5551234567');
$phone->getNumber(); // Returns "+15551234567"
$phone->getNationalNumber(); // Returns "5551234567"
$phone->getFormattedNumber(); // Returns "(555) 123-4567"
$phone->getCountry(); // Returns "US"
$phone->getCountryCallingCode(); // Returns "1"

Handling invalid numbers

Sometimes you may have bad data, it happens. To handle this, simply check to see if null was returned., (*14)

if (! $phone = Phone::getPhone('123')) {
    echo "Invalid number provided.";
}

Support

Need help? Create an issue., (*15)

The Versions

21/05 2018

dev-master

9999999-dev https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

v4.0.1

4.0.1.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

dev-hotfix/add-codeclimate-config

dev-hotfix/add-codeclimate-config https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

dev-hotfix/remove-exception-tests

dev-hotfix/remove-exception-tests https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

v4.0.0

4.0.0.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

dev-laravel-5.6

dev-laravel-5.6 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

dev-feature/increase-coverage

dev-feature/increase-coverage https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018

dev-hotfix/fix-cc-reporting

dev-hotfix/fix-cc-reporting https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

21/05 2018
21/05 2018

dev-feature/bump-twilio

dev-feature/bump-twilio https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

28/11 2017
16/11 2017
16/11 2017
28/09 2017
16/08 2017

v3.0.0

3.0.0.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

26/01 2017

v2.0.0

2.0.0.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

11/01 2017

v1.0.1

1.0.1.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

11/01 2017

v1.0.0

1.0.0.0 https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone

11/01 2017

v0.1.0-alpha

0.1.0.0-alpha https://github.com/ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation formatter format twilio phone