1.0.2 • Published 7 months ago

joi-phone-number-validation v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Joi Phone Number

Joi Phone Number is validation rule for Joi.

Latest Stable Version License NPM Downloads NPM Downloads

Installation

$ npm i joi-phone-number-validation

Usage

const { JoiPhoneNumber, RETURNING_FORMAT } = require("joi-phone-number-validation");

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.NATIONAL,
});
const { value, error } = schema.validate('+2010 605 944 88');   // 010 60594488

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.INTERNATIONAL,
});
const { value, error } = schema.validate('+2010 605 944 88');   // +20 10 60594488

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.ORIGINAL,
});
const { value, error } = schema.validate('+2010 605 944 88');   // +2010 605 944 88

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.FORMATTED_VALUE,
});
const { value, error } = schema.validate('+2010 605 944 88');   // +201060594488

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.RFC3966,
});
const { value, error } = schema.validate('+2010 605 944 88');   // tel:+201060594488

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT['E.164'],
});
const { value, error } = schema.validate('+2010 605 944 88');   // +201060594488

const schema = JoiPhoneNumber.string().phoneNumber({
  returningFormat: RETURNING_FORMAT.VALUE_WITH_EXTRA_INFO,
});
const { value, error } = schema.validate('+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.

1.0.2

7 months ago

1.0.1

8 months ago

1.0.0

8 months ago