How to validate phone number using PHP?

How to validate phone number using PHP?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to validate phone number using PHP?

Validating a phone number in PHP requires more than just checking for digits. You need to account for international formats, national prefixes, and common formatting conventions like leading zeros or plus signs. The most straightforward approach is leveraging the Intl extension, specifically the NumberFormatter class, which handles complex locale-specific rules without requiring you to maintain a massive list of regex patterns.

First, ensure the intl extension is enabled in your environment. You can verify this by running php -m | grep intl. If it's missing, install it via your package manager or PHP build tools. Once available, you can instantiate a formatter for a specific region and test if a string conforms to that region's expected format.

Consider the following example using NumberFormatter:

<?php

if (!extension_loaded('intl')) {
    die('Intl extension is not loaded.');
}

$phoneNumber = "+1 (555) 123-4567";
$locale = "en_US"; // Example: United States

// Create a formatter for the specific locale
$formatter = new NumberFormatter($locale, NumberFormatter::PHONE_NUMBER);

// Test if the number is valid for this locale
$isValid = $formatter->parse($phoneNumber, NumberFormatter::PARSE_ANY) !== false;

if ($isValid) {
    echo "The phone number is valid for $locale.";
} else {
    echo "The phone number is invalid.";
}

This approach is robust because it relies on the ICU library's data, which is kept up to date with changes in numbering plans. However, it has limitations. It validates whether a number could be valid for a region, but it doesn't guarantee that the number is currently assigned or active. That requires checking carrier databases, which is beyond the scope of simple validation logic.

Another common pattern involves regular expressions. While regex gives you fine-grained control over specific formats, writing one that covers every country's requirements is error-prone and difficult to maintain. A typical US-only regex might look like this: /^\+?1?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$/. This works for North American Numbering Plan (NANP) numbers but fails immediately when a user enters a UK or German number.

If you are building a global application, relying solely on regex is risky. You might accept a valid-looking number that belongs to a country your system doesn't support, or reject a legitimate international number because your pattern expects a local prefix instead of the country code. The NumberFormatter approach abstracts this complexity away from you.

There is also the question of normalization. Users often input numbers with spaces, dashes, parentheses, or even in different scripts (like Cyrillic characters that look like Latin digits). Before validation, consider normalizing the input using functions like preg_replace to strip non-digit and non-plus characters, then pass the cleaned string to your formatter. However, be careful not to over-normalize; stripping the leading plus sign might break international parsing logic if the library expects it.

In the Laravel ecosystem, you can wrap this logic into a custom validation rule or use third-party packages like tymon/validator or similar utilities that integrate with the framework's validation pipeline. For high-volume applications, consider caching the result of expensive locale lookups or using a dedicated phone number library if you need to handle thousands of entries per minute.

Ultimately, the choice between regex and the Intl extension depends on your needs. If you need strict adherence to a specific format string, regex works. But for general-purpose validation across multiple regions, the NumberFormatter is the superior tool because it delegates the complexity of global numbering plans to a well-tested library rather than reinventing the wheel with brittle code.

Our network