Run an HLR lookup
Structural validity ends here. The number is well-formed, and it fits its country's plan. An HLR lookup provides a point-in-time network-level signal about whether a mobile number appears active, inactive, unreachable, ported, roaming or unknown, depending on market and data availability.
Send the normalised E.164 string to a service such as Acudo and read the network response. An HLR lookup returns response codes, and the codes that carry most of the weight report whether the number is live and reachable. Format validation catches roughly 70 to 80 percent of bad numbers, the cheap and obvious ones, while a live network check removes the disconnected and non-mobile lines that pass a format check cleanly.
Treat the result as a point-in-time answer. A number that appears active today can be disconnected, reassigned, or changed later, so validate at entry and revalidate before large or important sends.
Return useful validation results
A boolean is the wrong return type. Your caller needs to know why something failed, because the fix for each failure is different. Define four outcomes and return the reason alongside them.
-
Malformed: cleaning produced something that isn't a number, or the extension parse failed
-
Impossible: the digit count or prefix can't exist in the resolved country
-
Structurally valid: no network check performed or the check was inconclusive
-
Unsuitable or unreachable: structurally correct, but line-type or network-level checks indicate the number is inactive, unreachable, non-mobile or otherwise unsuitable for the intended communication.
Alongside the verdict, store the raw input exactly as it arrived and the normalised E.164 result as separate fields. E.164 is the international standard format for phone numbers: a plus sign, country code, and subscriber number with no spaces or punctuation. Do not overwrite the raw value before the normalised result has been reviewed and mapped correctly, because if normalization goes wrong and the original is gone, you have no way back.
Silent transformation is the failure mode to avoid. If your pipeline had to guess a country, say so in the result. A record that quietly became a UK number because nobody supplied context will pass every check you run and fail every message you send.
Add real-time feedback
Timing is the whole game with inline validation for a phone number validator. Baymard Institute's testing found that when validation fires too early, participants' typing was disrupted as they stopped to read an error, and some concluded their perfectly valid input was wrong. Validate when the field loses focus, or once enough digits exist to make a judgment.
Once an error is showing, though, the rules invert. Baymard's recommendation is that the message must live-update on a keystroke level and disappear the moment the input becomes valid. Nothing frustrates a person faster than a corrected field still shouting at them.
Put the correction next to the field while the number and the country selector are both still on screen. "This looks too short for the United Kingdom" gives someone a route forward. "Invalid phone number" gives them a reason to leave.
Test phone number validator rules
Build a fixture file and run it in continuous integration, because these phone number validator rules break silently when a dependency updates or someone refactors the cleaning step. Cover the cases that actually appear in production data.
Feed in an invalid country code and confirm the resolution step fails cleanly instead of throwing. Then include a well-formed number that no carrier has assigned. Ofcom reserves 07700 900000–07700 900999 for fictitious use in TV, film, and fiction, so a number in that range passes structural validation and is caught only by your reachability layer, which makes it a precise test of whether that layer is wired up at all.
Where validation earns its keep
The phone number validator rules in this article stack: cleaning removes the noise, and the network check answers the only question that matters before you send.
Acudo is a specialist validation partner that confirms whether numbers are correctly formatted and whether they reach real, active subscribers, without the overhead of full CPaaS complexity. Speak to Acudo about mobile validation workflows if your phone number validator needs to prove reachability.