stuyam / laravel-phone-validator by stuyam

A phone validator for Laravel using the free Twilio phone lookup service.
58,982
28
4
Package Data
Maintainer Username: stuyam
Maintainer Contact: stuartyamartino@gmail.com (Stuart Yamartino)
Package Create Date: 2016-06-29
Package Last Update: 2024-10-20
Home Page: https://packagist.org/packages/stuyam/laravel-phone-validator
Language: PHP
License: MIT
Last Refreshed: 2024-11-16 15:02:46
Package Statistics
Total Downloads: 58,982
Monthly Downloads: 87
Daily Downloads: 0
Total Stars: 28
Total Watchers: 4
Total Forks: 8
Total Open Issues: 0

Lavarel Phone Validator

Packagist Packagist

A phone validator for Laravel using the FREE Twilio phone lookup service

This custom validator validates that a phone number actual exists. Not just if it has a specific format or not, but if the phone number is a real registered phone number. It is smart enough to handle formated numbers like (123)-555-1234 and unfromated numbers like 1235551234 so users can enter in a phone number however they are most comfortable.

For a working example check out Laravel Validator Example project.

Also see: Laravel Kickbox Validator for email address validation.

Step 1

Install via composer:

composer require stuyam/laravel-phone-validator

Step 2

Add to your config/app.php service provider list:

StuYam\PhoneValidator\PhoneValidatorServiceProvider::class

Step 3

Add Twilio credentials to your .env file:

(If you don't have a Twilio account you can go to Twilio.com and make a free account)

TWILIO_SID=xxxxxxxx
TWILIO_TOKEN=xxxxxxxx

Usage

Add the string 'phone' to a form request rules or validator like so:

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class PhoneFormRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
        	// this means the phone input will be validated that
        	// it is required and that it is an ACTUAL phone number
            'phone' => 'required|phone'
        ];
    }
}