Phone
Format country-aware phone numbers with optional extension
Phone
The phone formatter formats national phone numbers per country and appends an optional extension for extra digits.
Options
| Option | Default | Description |
|---|---|---|
country | "US" | US, CA, IN, GB, FR, DE, AU, BR, JP |
pattern | country mask | Custom mask, e.g. "(###) ###-####" |
prefix | country prefix | e.g. "+1 ", "+91 " (empty for some countries) |
ext | false | Append an extension when extra digits are typed |
extSeparator | " ext. " | Separator before the extension |
extDigits | 5 | Max extension digits |
Usage
validationSchema: {
phone: {
format: { type: "phone", options: { country: "US", ext: true } },
phone: true, // validate the formatted value
},
}Results
| Country | Typed | Result |
|---|---|---|
US | 5551234567 | (555) 123-4567 |
US + ext | 555123456789 | (555) 123-4567 ext. 89 |
IN | 9876543210 | +91 98765 43210 |
DE | 1512345678 | +49 151 2345678 |
Things to know
- Extra digits beyond the country mask only appear when
ext: true. - Pair with the
phonevalidator for full format validation.