adsign

payload phone number plugin

by adsign
Custom fields
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds a phoneNumberField to Payload that uses libphonenumber-js to format and validate phone numbers per country. It is enabled through a plugin in the config, with project-wide or per-field allowed countries and default country. Numbers are stored in E.164 format and returned as objects with national and international forms. Requires Payload 3 and an import map regeneration.

Features

  • As-you-type formatting and validation based on the selected country
  • Limit selectable countries and set a default country per field or project-wide
  • Automatic region detection when pasting international numbers
  • Configurable table cell format: E.164, national or international
  • Generated TypeScript types and stored E.164 values
  • Context flag to return the raw string instead of the parsed object

Use cases

  • Collect validated contact numbers for employees or customers in a specific set of countries
  • Normalize phone numbers to E.164 for querying and integration with messaging services

From the author

Phone Number Plugin for Payload CMS.

Installation

npm i payload-phone-number-plugin

17

Stars

1

Forks

3

Open Issues

1 weeks ago

Last Updated

698

Weekly Downloads

v1.7.1

npm Version

247.6 KB

Unpacked Size

3

Dependencies

GitHub stars

17+2 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 202617
Dec 4, 202617
Dec 3, 202617
Dec 2, 202617
Dec 1, 202617
Nov 30, 202617
Nov 29, 202617
Nov 28, 202617
Nov 27, 202617
Nov 26, 202617
Nov 25, 202617
Nov 24, 202617
Nov 23, 202617
Nov 22, 202617
Nov 21, 202617
Nov 20, 202617
Nov 19, 202617
Nov 18, 202617
Nov 17, 202617
Nov 16, 202617
Nov 15, 202617
Nov 14, 202617
Nov 13, 202617
Nov 12, 202617
Nov 11, 202617
Nov 10, 202617
Nov 9, 202617
Nov 8, 202617
Nov 7, 202617
Nov 6, 202617
Nov 5, 202617
Nov 4, 202616
Nov 3, 202616
Nov 2, 202616
Nov 1, 202616
Oct 31, 202616
Oct 30, 202616
Oct 29, 202616
Oct 28, 202616
Oct 27, 202616
Oct 26, 202616
Oct 25, 202616
Oct 24, 202616
Oct 23, 202616
Oct 22, 202616
Oct 21, 202616
Oct 20, 202616
Oct 19, 202616
Oct 18, 202616
Oct 17, 202616
Oct 16, 202616
Oct 15, 202616
Oct 14, 202616
Oct 13, 202616
Oct 12, 202616
Oct 11, 202616
Oct 10, 202616
Oct 9, 202615
Oct 8, 202615
Oct 7, 202615
Oct 6, 202615
Oct 5, 202615
Oct 4, 202615
Oct 3, 202615
Oct 2, 202615
Oct 1, 202615
Sep 30, 202615
Sep 29, 202615
Sep 28, 202615
Sep 27, 202615
Sep 26, 202615
Sep 25, 202615
Sep 24, 202615
Sep 23, 202615
Sep 22, 202615
Sep 21, 202615
Sep 20, 202615
Sep 19, 202615
Sep 18, 202615
Sep 17, 202615
Sep 16, 202615
Sep 15, 202615
Sep 14, 202615
Sep 13, 202615
Sep 12, 202615
Sep 11, 202615
Sep 10, 202615
Sep 9, 202615
Sep 8, 202615
Sep 7, 202615
Sep 6, 202615
npm weekly downloads

682+151 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026682
Dec 4, 2026712
Dec 3, 2026700
Dec 2, 2026628
Dec 1, 2026649
Nov 30, 2026616
Nov 29, 2026566
Nov 28, 2026692
Nov 27, 2026526
Nov 26, 2026625
Nov 25, 2026810
Nov 24, 2026805
Nov 23, 20261,158
Nov 22, 20261,545
Nov 21, 20261,444
Nov 20, 20261,562
Nov 19, 20261,452
Nov 18, 20261,313
Nov 17, 20261,287
Nov 16, 2026945
Nov 15, 2026613
Nov 14, 2026650
Nov 13, 2026690
Nov 12, 2026784
Nov 11, 2026747
Nov 10, 2026765
Nov 9, 2026765
Nov 8, 2026910
Nov 7, 2026900
Nov 6, 2026863
Nov 5, 2026805
Nov 4, 2026950
Nov 3, 2026930
Nov 2, 2026965
Nov 1, 2026922
Oct 31, 2026894
Oct 30, 2026796
Oct 29, 2026692
Oct 28, 2026452
Oct 27, 2026454
Oct 26, 2026410
Oct 25, 2026221
Oct 24, 2026126
Oct 23, 202672
Oct 22, 2026127
Oct 21, 2026212
Oct 20, 2026211
Oct 19, 2026206
Oct 18, 2026197
Oct 17, 2026184
Oct 16, 2026204
Oct 15, 2026174
Oct 14, 2026154
Oct 13, 2026164
Oct 12, 2026172
Oct 11, 2026255
Oct 10, 2026294
Oct 9, 2026321
Oct 8, 2026321
Oct 7, 2026315
Oct 6, 2026322
Oct 5, 2026322
Oct 4, 2026273
Oct 3, 2026236
Oct 2, 2026227
Oct 1, 2026416
Sep 30, 2026385
Sep 29, 2026385
Sep 28, 2026394
Sep 27, 2026459
Sep 26, 2026466
Sep 25, 2026446
Sep 24, 2026257
Sep 23, 2026255
Sep 22, 2026265
Sep 21, 2026255
Sep 20, 2026185
Sep 19, 2026163
Sep 18, 2026213
Sep 17, 2026242
Sep 16, 2026270
Sep 15, 2026278
Sep 14, 2026320
Sep 13, 2026341
Sep 12, 2026374
Sep 11, 2026386
Sep 10, 2026392
Sep 9, 2026414
Sep 8, 2026515
Sep 7, 2026559
Sep 6, 2026531

Each point is npm's rolling 7-day download count.

Health Score

68/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/909766798-root.svg)](https://payloaddirectory.dev/plugins/909766798-root)
HTML
<a href="https://payloaddirectory.dev/plugins/909766798-root"><img src="https://payloaddirectory.dev/badge/909766798-root.svg" alt="Payload Directory"></a>
Updated Nov 27, 2026Created Dec 29, 2024Published Jul 22, 2026

README

Payload CMS Phone Number Plugin

Payload CMS NPM Version

This Payload CMS plugin uses libphonenumber-js to format and validate phone numbers.

Preview

Features

  • Format phone numbers to multiple formats (E.164, national, international)
  • As-you-type formatting based on selected country
  • Validates phone numbers based on selected country
  • Support for limiting selection to only some countries (per-field or project-wide)
  • Support for setting a default country (per-field or project-wide)
  • Automatic formatting and region detection when pasting international phone numbers
  • Full TypeScript support with generated phone number types
  • Built with Payload UI components so it feels native to the Admin Panel
  • i18n support for validation messages (PRs for new languages are welcome)

Installation

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:importmap since this plugin adds a custom component

Plugin Options

NameTypeRequiredDescription
allowedCountriesRegionCode[]falseRestricts every phoneNumberField in the project to these country codes. Individual fields can narrow further but cannot allow countries outside this list.
defaultCountryRegionCodefalseProject-wide default country. Field-level defaultCountry overrides this. Type-narrowed by allowedCountries.
admin.cellDisplayFormat'e164' | 'national' | 'international'falseProject-wide default for admin.cellDisplayFormat. Field-level value overrides this.
admin.countryPrefixDisplayFormat'flagEmoji' | 'callingCode' | 'flagEmojiAndCallingCode'falseProject-wide default for admin.countryPrefixDisplayFormat. Field-level value overrides this.

Example: project-wide allowed countries and default

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:types for the type narrowing to take effect.

Field Props

NameTypeRequiredDescriptionDefault
defaultCountryRegionCodefalseThe default country region code for the field (ISO 3166-1 alpha-2)'US'
allowedCountriesRegionCode[]falseArray of allowed country codes. If specified, restricts user selection to these countries only
admin.cellDisplayFormat'e164' | 'national' | 'international'falseThe format to display phone numbers in table cells'international'
admin.countryPrefixDisplayFormat'flagEmoji' | 'callingCode' | 'flagEmojiAndCallingCode'falseThe format to display the country prefix next to the field input'flagEmojiAndCallingCode'

Example with Default Country

phoneNumberField({
  name: 'phoneNumber',
  label: 'Phone Number',
  defaultCountry: 'NO', // Norway will be pre-selected
})

Example with Allowed Countries

phoneNumberField({
  name: 'phoneNumber',
  label: 'Phone Number',
  allowedCountries: ['NO', 'US', 'SE'], // Only these countries will be selectable
})

Example with Default Country and Allowed Countries

phoneNumberField({
  name: 'phoneNumber',
  label: 'Phone Number',
  defaultCountry: 'NO', // Norway will be pre-selected
  allowedCountries: ['NO', 'US', 'SE'], // Only these countries will be selectable
})

Example with Cell Display Format

phoneNumberField({
  name: 'phoneNumber',
  label: 'Phone Number',
  admin: {
    cellDisplayFormat: 'e164', // Display as +4712345678 in table cells
  },
})

Example with Country Prefix Display Format

phoneNumberField({
  name: 'phoneNumber',
  label: 'Phone Number',
  admin: {
    countryPrefixDisplayFormat: 'callingCode', // Display only +47 (no flag emoji)
  },
})

Creating Documents Programmatically

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.

Using the Local API or the Payload REST API SDK

await payload.create({
  collection: 'employees',
  data: {
    phoneNumber: '+4712345678'
  }
})

Using REST API

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.

Querying by Phone Number

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.

TypeScript Types

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"
  }
}

Get the raw phone number value

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"
}

Additional Information

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

Similar plugins