Is there a comprehensive guide on validating phone inputs gracefully in an input field (for all the countries in the world)?

Every country seems to have a different number of digits for the actual phone number, different style of writing, different length of country code (1, 2, or 3 digits), and optionally featuring an extension code too.


To an extent, regulation can affect this too over time. Maybe one country decides they want to add (or remove) an extra digit because reasons (unlikely and infrequent, but you know, edge cases).

@celia i think the only true validation is to text/call it.

but for reliably getting accurate phone numbers globally, the following three items are significant to appear in the UI:

1. the flag emojis
2. +(country code)
3. country name

a hint for the other digits are helpful too


@tychi yeah, I've seen xxx-xxx-xxxx in the US context, but we just go xxxxxxxxxx in India. Idk if there is even an official guide on this internationally, or it's just culture in each country dictating it, even regardless of any official guideline. That would be hard to capture.

I'd love an input that is able to suggest an apt placeholder once a country is selected.

@celia @tychi I am using this one in my application

Dont remember where i found it (somewhere on stack owerflow). It worked for my needs so i saved it...

@celia @tychi Oh, do you mean to include the style of writing them, not just what the valid digits are? In that case, no, it’s just whatever people happen to make up. There is an official standard (E.163 from memory?), but it’s way more than narrow.

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.