Phone numbers must handle country codes and format variants
Aliases: E.164 · international prefix · phone input
What it is
A phone number in someone’s hands is a string with spaces, hyphens, parentheses, leading zeros, and +. In a system it usually has to land on one dialable representation. Handling country codes and format variants means the input layer must accept both local forms (010-6552-xxxx, (415) 555-…) and international forms (+86 …, 00 44 …), and store country code apart from the national number—not block everyone with “11 digits.” How an address is split, and how many segments a name has, are not the phone problem. Whether display groups digits is not a reason the input may only take unspaced numbers.
Why it happens
People recall a number as they heard it or copied it; they do not wash it into canonical digits first. Validation that allows one length only, or that forbids + and spaces, kills legal numbers at the input layer. A second layer is conflict between country code and national prefix. In China the domestic form writes 010, the international form +86 10; in the UK, 020 versus +44 20. Both prefixes must not appear in one canonical value, but input must allow either writing. Without a country picker, + is the only stable international cue. Forcing “pick a flag, then type a local number” is unfriendly to people who only remember the international form; a single borderless digit box cannot explain a leading zero either. Three boxes (country, area, number) become a hollow shell in countries that dropped area codes. A stable input is a punctuation-tolerant string plus explicit country context, normalized at store time.
Studying it
Have people fill using the string as stored in their own contacts, not digits the experimenter printed. Compare pure digit-length validation, a country picker, and allowing + and spaces then parsing.
Independent variables: punctuation and + allowed, how country code is supplied (picker / parsed from + / assumed current country), whether a national leading zero is stripped.
Dependent variables: the person’s own number rejected, whether both international and local writings pass, whether the normalized value can be dialed or receive SMS, country code typed into the number box and duplicated.
Printed 11-digit lab sheets fake that length checks suffice. Use paste from contacts. Whether an SMS code actually arrives is a harder dependent variable than whether the format looks nice.
Where it stops holding
An internal extension list in one country, where the carrier guarantees unique length, may use fixed length—but should still accept pasted spaces. Extensions (;1234, ext. 12) are not country codes; mixing them into the same box breaks normalization. Emergency numbers, short codes, and service numbers are far shorter than ordinary mobiles; mobile rules will kill them. Speech input will contain words like “plus eight six” and needs another parser, not keystroke filtering alone.
Applying it
- Allow spaces, hyphens, parentheses, and a leading
+in the phone input. Validate after stripping punctuation; do not forbid those characters on keypress. - Country context must be explicit: a picker or parse from
+. Do not default to “everyone is 11 domestic digits.” Drop the national leading zero when normalizing to an international form; do not make the user decide whether to drop it. - A whole string pasted from contacts should parse in one shot; do not require people to delete spaces first.
- Verify by pasting a parenthesized US number from contacts, a
+86Chinese number, and the same number with a national leading zero—all three must normalize to a dialable value. Block a domestic number with spaces using “must be 11 digits” as the do-not-ship control. Send a verification code to the normalized number; passing format is not enough.
Related
- Within the group: H1.10.1 Address format changes by region; fields cannot be fixed · H1.10.3 Names must not assume order or count of given and family names
- Adjacent: S2.07 Telephone number formats · E2.07 Input masks · H6.03 OTP and passwordless login
- Search terms:
phone number·country code·E.164