Phone formats

Phone number formatting for test data

A country calling code, a presentation mask, and a valid phone number are different things.

Content updated: · Maintainer and corrections

Build a three-part phone-field test

For Taiwan, choose +886 in the calling-code field and keep the national input separate. Use the country page’s masked mobile layout to inspect spacing and wrapping. Then copy its deliberately overlong test value to exercise the invalid-input message. The layout example and rejection input serve different test assertions.

Check that the calling code is not duplicated when saving or copying. Check that a rejected value stays visible so the user can correct it. For a successful SMS flow, use the provider’s documented sandbox fixtures and delivery controls; do not derive a routable number from this site’s mask.

Build a three-part phone-field test
CaseInterpretation and next step
MaskChecks grouping, labels, wrapping and placeholders.
Deliberately invalid valueChecks rejection and error recovery; it must not trigger delivery.
Provider sandbox fixtureChecks the integration in the provider's controlled environment.

Store a canonical representation

For systems that handle phone data, use a documented international representation such as E.164 when it is appropriate for the product. Apply local spacing and grouping only for display.

Keep test values non-routable

A plausible-looking number can still reach someone. Use a deliberately invalid value or an environment-specific test range, and do not treat a format mask as a validation rule.

Read a country page before using the mask

Norway's mobile example is grouped as +47 XX XX XX XX, while Taiwan's is +886 XXX XXX XXX. Both are display examples from libphonenumber, not exhaustive rules for every number type or prefix. Check the country page's source and the number category required by your product.

The separate generated number exceeds the national length accepted by the bundled metadata. It is useful for a form's invalid-input state, but its grouping is not a sample of a valid local number. Keep a real calling workflow out of tests.

Norway mobile display: +47 XX XX XX XX
Taiwan mobile display: +886 XXX XXX XXX
X = display placeholder, not a digit to dial

Data provenance

Sources