@boelensman1/joi-phone

1.0.0 • Public • Published

joi-phone-number

Phone number validation rule for Joi

Build Status Greenkeeper badge

What

Allows you to do Joi.phoneNumber().

Uses https://github.com/ruimarinho/google-libphonenumber for validation.

Which is a compiled version of the Google library https://github.com/googlei18n/libphonenumber.

How

const myCustomJoi = Joi.extend(require('joi-phone-number'));

myCustomJoi.phoneNumber().validate('+32494567324');

// The phone number can be transformed to a custom format
// Note that this follows Joi's `convert` option
myCustomJoi.phoneNumber().defaultCountry('BE').format('e164').validate('494322456'); // '+32494322456'
myCustomJoi.phoneNumber()defaultCountry('BE').format('international').validate('494322456'); // '+32 494 32 24 56'
myCustomJoi.phoneNumber()defaultCountry('BE').format('national').validate('494322456'); // '0494 32 24 56'
myCustomJoi.phoneNumber()defaultCountry('BE').format('rfc3966').validate('494322456'); // 'tel:+32-494-32-24-56'
myCustomJoi.phoneNumber()defaultCountry('US').strictValidation().validate('7777777777'); // validation error
myCustomJoi.phoneNumber()defaultCountry('US').validate('7777777777'); // 7777777777

Package Sidebar

Install

npm i @boelensman1/joi-phone

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

12 kB

Total Files

6

Last publish

Collaborators

  • boelensman1