Socket
Book a DemoInstallSign in
Socket

zod-phone-number

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-phone-number

Zod Phone Number is validation schema for Zod

latest
npmnpm
Version
1.0.2
Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

Zod Phone Number

Zod Phone Number is validation schema for Zod.

Latest Stable Version License NPM Downloads NPM Downloads

Features

  • Seamlessly integrates with Zod's validation framework.
  • Supports multiple phone number formats, including National, International, RFC3966, and E.164.
  • Provides detailed phone number metadata, such as country code and formatted numbers.
  • Easy-to-use API for handling phone number validation in your applications.

Installation

$ npm i zod-phone-number

Usage

const { ZodPhoneNumber, RETURNING_FORMAT } = require('zod-phone-number');

const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.NATIONAL,
}).safeParse('+2010 605 944 77'); // 010 60594488


const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.INTERNATIONAL,
}).safeParse('+2010 605 944 88'); // +20 10 60594488

const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.ORIGINAL,
}).safeParse('+2010 605 944 88'); // +2010 605 944 88

const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.FORMATTED_VALUE,
}).safeParse('+2010 605 944 88'); // +201060594488

const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.RFC3966,
}).safeParse('+2010 605 944 88'); // tel:+201060594488

const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT['E.164'],
}).safeParse('+2010 605 944 88'); // +201060594488


const { data } = ZodPhoneNumber.phoneNumber({
  returningFormat: RETURNING_FORMAT.VALUE_WITH_EXTRA_INFO,
}).safeParse('+2010 605 944 88');
/*
output: {
        countryCode: 'EG',
        formattedNumber: '+201060594488',
        nationalNumber: '1060594488',
        originalValue: '+2010 605 944 88',
        countryCallingCode: '20',
      }
*/

Tests

To run the test suite, first install the dependencies then run npm test:

$ npm install
$ npm test

Support

Feel free to open issues on github.

Keywords

zod

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts