npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-phone-number-plugin

v1.5.1

Published

Phone Number Plugin for Payload CMS.

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
  • Support for setting a default country
  • 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

Field Props

| 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' |

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