Phone parser and formatter
Parse, validate and format phone numbers. Get information about the phone number, like the country code, type, etc.
About Phone parser and formatter
Parses a phone number with Google's libphonenumber rules: tells you the country and calling code, whether the number is valid or merely possible, its type (mobile, fixed line, toll-free...), and formats it in international, national, E.164 and RFC 3966 styles.
When you would use it
- Normalising phone numbers collected from a form into E.164 (+886912345678) before storing them.
- Checking whether a number is valid for its country and whether it is a mobile that can receive SMS.
- Formatting a number for display in the local or international convention.
How to use it
- Choose the default country, used when the number has no + prefix; it is preselected from your browser language.
- Type the number in any common form (spaces, dashes, parentheses, leading 0 or +).
- Read the country, validity, type and the four formats, and copy the one you need.
Things worth knowing
- Possible means the length fits the country's patterns; valid means the number matches an actually assigned range. Store E.164 only for valid numbers.
- A number without + is interpreted in the default country, so 0912 345 678 is Taiwanese with Taiwan selected and invalid with another country selected.
- Type detection (mobile versus fixed line) is reliable in most countries but ambiguous in some, notably the United States, where both share the same ranges.
- Numbering plans change; the library is updated regularly but a brand-new range may be reported as invalid for a while.
Frequently asked questions
- Which format should I store in a database?
- E.164: a plus sign, the country code and the national number with no spaces (+886912345678). It is unambiguous and what SMS and telephony APIs expect.
- Why is a number I can call reported as invalid?
- Either the default country is wrong for a number without +, or the number belongs to a range the library does not yet know. Try adding the country code with + to rule out the first cause.