Adds a phoneNumberField to Payload that formats and validates phone numbers per country using libphonenumber-js. Numbers are stored as E.164 strings and returned as objects with national and international formats. Countries can be limited and a default set per field or project-wide. Requires Payload 3 and an import map regeneration.
Phone Number Plugin for Payload CMS.
Installation
npm i payload-phone-number-plugin16
Stars
1
Forks
3
Open Issues
4 days ago
Last Updated
114
Weekly Downloads
v1.7.1
npm Version
247.6 KB
Unpacked Size
3
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/909766798-root)<a href="https://payloaddirectory.dev/plugins/909766798-root"><img src="https://payloaddirectory.dev/badge/909766798-root.svg" alt="Payload Directory"></a>README
This Payload CMS plugin uses libphonenumber-js to format and validate phone numbers.

Install the payload-phone-number-plugin package into your project
pnpm install payload-phone-number-plugin
Add the plugin to your Payload Config:
import { phoneNumberPlugin } from 'payload-phone-number-plugin';
export const config = buildConfig({
plugins: [
phoneNumberPlugin(),
]
});
Then you can use the phone number field:
import { phoneNumberField } from 'payload-phone-number-plugin';
const Employees: CollectionConfig = {
slug: 'employees',
fields: [
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
required: true,
}),
]
};
[!NOTE] Remember to update your importMap with
generate:importmapsince this plugin adds a custom component
| Name | Type | Required | Description |
|---|---|---|---|
allowedCountries | RegionCode[] | false | Restricts every phoneNumberField in the project to these country codes. Individual fields can narrow further but cannot allow countries outside this list. |
defaultCountry | RegionCode | false | Project-wide default country. Field-level defaultCountry overrides this. Type-narrowed by allowedCountries. |
admin.cellDisplayFormat | 'e164' | 'national' | 'international' | false | Project-wide default for admin.cellDisplayFormat. Field-level value overrides this. |
admin.countryPrefixDisplayFormat | 'flagEmoji' | 'callingCode' | 'flagEmojiAndCallingCode' | false | Project-wide default for admin.countryPrefixDisplayFormat. Field-level value overrides this. |
phoneNumberPlugin({
allowedCountries: ['NO', 'SE', 'DK', 'US'],
defaultCountry: 'NO',
})
Field-level values override these defaults. defaultCountry and field-level allowedCountries are constrained to a subset of the plugin's allowedCountries.
[!NOTE] Run
payload generate:typesfor the type narrowing to take effect.
| Name | Type | Required | Description | Default |
|---|---|---|---|---|
defaultCountry | RegionCode | false | The default country region code for the field (ISO 3166-1 alpha-2) | 'US' |
allowedCountries | RegionCode[] | false | Array of allowed country codes. If specified, restricts user selection to these countries only | |
admin.cellDisplayFormat | 'e164' | 'national' | 'international' | false | The format to display phone numbers in table cells | 'international' |
admin.countryPrefixDisplayFormat | 'flagEmoji' | 'callingCode' | 'flagEmojiAndCallingCode' | false | The format to display the country prefix next to the field input | 'flagEmojiAndCallingCode' |
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
defaultCountry: 'NO', // Norway will be pre-selected
})
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
allowedCountries: ['NO', 'US', 'SE'], // Only these countries will be selectable
})
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
defaultCountry: 'NO', // Norway will be pre-selected
allowedCountries: ['NO', 'US', 'SE'], // Only these countries will be selectable
})
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
admin: {
cellDisplayFormat: 'e164', // Display as +4712345678 in table cells
},
})
phoneNumberField({
name: 'phoneNumber',
label: 'Phone Number',
admin: {
countryPrefixDisplayFormat: 'callingCode', // Display only +47 (no flag emoji)
},
})
When creating or updating documents, pass the phone number as an E.164 string directly. Phone numbers are stored in E.164 format in the database.
The field will handle parsing and validation so it won't save unless it's a valid phone number for that field.
await payload.create({
collection: 'employees',
data: {
phoneNumber: '+4712345678'
}
})
await fetch('http://localhost:3000/api/employees', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
phoneNumber: '+4712345678'
})
})
[!NOTE] You cannot pass a phone number object, only E.164 strings are accepted.
When using payload.find or database queries, use the E.164 format:
const employees = await payload.find({
collection: 'employees',
where: {
phoneNumber: {
equals: '+4712345678'
}
}
})
The same applies when using the REST API.
The field is typed as string | PhoneNumber, similar to Payload's relationship fields with depth.
This is because phone numbers are stored as strings in the database but are transformed into objects when you read them using libphonenumber.
export interface PhoneNumber {
e164: string;
regionCode: string;
callingCode: string;
national: string;
international: string;
}
export interface Employee {
phoneNumber: string | PhoneNumber;
}
Example response:
{
"phoneNumber": {
"e164": "+4712345678",
"regionCode": "NO",
"callingCode": "+47",
"national": "12 34 56 78",
"international": "+47 12 34 56 78"
}
}
If you need to access the raw phone number value you can use context when you query:
const employees = await payload.find({
collection: 'employees',
where: {
phoneNumber: {
equals: '+4712345678'
}
},
context: {
phoneNumberPluginReturnRawValue: true,
},
})
Example response:
{
"phoneNumber": "+4712345678"
}
A region code is an ISO 3166-1 alpha-2 code.
List of all valid region codes can be found here: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
templates
Managed template documents with editable content and template-backed fields that inherit defaults
550/wk0v4
payload google map autocomplete places
Google Places autocomplete field for Payload CMS collections with automatic coordinate capture
470/wk28v2
payload plugin reading time
Computed reading time and word count fields for Lexical rich-text content in Payload collections
410/wk1v3
encrypted fields
Encrypt field values at rest in the database with a drop-in encryptedField helper
6955/wk83v3
payload icon picker
Icon picker field with searchable dropdown or drawer grid that stores the icon name and raw SVG
690/wk52v3
payload plugin json form builder
Edit a Payload JSON field as real admin fields using a builder inside the admin panel
580/wk29v3