Tutorial · PHP

Validate phone numbers in PHP

Validate and normalise phone numbers in plain PHP or Laravel, then enrich them with carrier and line type.

Updated October 1, 2026 · 2 min read

libphonenumber for PHP

composer require giggsey/libphonenumber-for-php
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;

$util = PhoneNumberUtil::getInstance();

try {
    $number = $util->parse('020 7946 0958', 'GB');
    var_dump($util->isValidNumber($number));                     // bool(true)
    echo $util->format($number, PhoneNumberFormat::E164);         // +442079460958
    echo $util->format($number, PhoneNumberFormat::INTERNATIONAL); // +44 20 7946 0958
} catch (NumberParseException $e) {
    // not a phone number at all
}

Carrier and line type with the numlookupapi API

function lookupPhone(string $number): array
{
    $ch = curl_init('https://api.numlookupapi.com/v1/validate/' . rawurlencode($number));
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => ['apikey: ' . getenv('NUMLOOKUP_API_KEY')],
        CURLOPT_TIMEOUT => 10,
    ]);
    $body = curl_exec($ch);
    curl_close($ch);
    return json_decode($body, true);
}

$result = lookupPhone('+14158586273');
echo $result['line_type']; // mobile
echo $result['carrier'];   // AT&T Mobility LLC

With Laravel’s HTTP client:

$result = Http::withHeaders(['apikey' => config('services.numlookup.key')])
    ->get('https://api.numlookupapi.com/v1/validate/' . rawurlencode($phone))
    ->throw()
    ->json();

A Laravel validation rule

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;

class ValidPhone implements ValidationRule
{
    public function __construct(private string $defaultRegion = 'US') {}

    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $util = PhoneNumberUtil::getInstance();
        try {
            if (! $util->isValidNumber($util->parse((string) $value, $this->defaultRegion))) {
                $fail('The :attribute is not a valid phone number.');
            }
        } catch (NumberParseException) {
            $fail('The :attribute is not a valid phone number.');
        }
    }
}
$request->validate(['phone' => ['required', new ValidPhone('GB')]]);

Need VoIP detection or the carrier at sign-up? Call the API in a queued job after validation and store line_type next to the E.164 number. Get a free API key.

Frequently asked questions

Which PHP library validates phone numbers?

giggsey/libphonenumber-for-php is the PHP port of Google's libphonenumber. Install it with composer require giggsey/libphonenumber-for-php.

How do I validate phone numbers in Laravel?

Write a custom rule that parses the number with libphonenumber and calls isValidNumber(), or use the propaganistas/laravel-phone package, which wraps the same library.

Phone number API

Validate numbers like this in your app

numlookupapi checks any phone number worldwide in one request and returns validity, line type, carrier, location and every standard format as JSON.

Read the documentation

100 free requests every month. No credit card required.

GET https://api.numlookupapi.com/v1/validate/+12069220880

{
  "valid": true,
  "number": "12069220880",
  "local_format": "2069220880",
  "international_format": "+12069220880",
  "country_prefix": "+1",
  "country_code": "US",
  "country_name": "United States of America",
  "location": "Seattle",
  "line_type": "landline",
  "e164_format": "+12069220880",
  "national_format": "(206) 922-0880"
}

Keep reading

Start using our Phone number API for free today!

Get 100 requests / month for free