joi-phone-validator

Add to Joi a phone number validator/formatter/parser

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
joi-phone-validator
211.0.08 years ago8 years agoMinified + gzip package size for joi-phone-validator in KB

Readme

= joi-phone-validator
A https://github.com/hapijs/joijoi extension used to validate/parse phone numbers.
Internally it is using Google's library https://github.com/googlei18n/libphonenumberlibphonenmber.
== Requirements
  • nodejs >= 4
  • npm >= 2

== Install
source,shell

.Add the dependency to your package.json

npm install joi-phone-validator --save

== Usage === Importing the lib
source,javascript

.Require the lib if using ES5

var phoneValidator = require('joi-phone-validator');

source,javascript

.Import the module if using ES6

import phoneValidator from 'joi-phone-validator'

=== Using the lib
source,javascript

.Validate phone number format

var schema = phoneValidator.phone().validate() var result = Joi.validate('+33123456789', schema) // result.error -> null

// result.value -> '+33123456789'

source,javascript

.Validate phone number is mobile

var schema = phoneValidator.phone().mobile() var result = Joi.validate('+33623456789', schema) // result.error -> null

// result.value -> '+33623456789'

source,javascript

.Functions are composable

var schema = phoneValidator.phone().validate().mobile()

For others use cases, you can look at the tests in the test directory.
== Run tests

source,shell

npm test

== Licence
link:LICENCEMIT