1.0.0 • Published 4 years ago

joi-ext-phone-number v1.0.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
4 years ago

joi-ext-phone-number

Joi extension for phone number rules.

This uses google-libphonenumber for validation. An alternative Joi extension for phone number validation that support for Joi v16+.

This extended from Joi.string() base. So allows you define schema by Joi.string().phoneNumber().

Compability

This Joi extension requires joi v16 or newer.

If you are unfamiliar with Joi, maybe you should read Joi Documentation and API

Installation

$ npm install joi-ext-phone-number --save

Usage

const Joi = require('@hapi/joi');
const customJoi = Joi.extend(require('joi-ext-phone-number'));

const schema = customJoi.string().phoneNumber();

// or by options
const customSchema = customJoi.string().phoneNumber({
  defaultRegionCode: 'US',
  format: 'e164',
  strict: false
});

For more usage, check it out under test directory.