1.0.0 • Published 8 years ago
joi-phone-validator v1.0.0
= joi-phone-validator
A https://github.com/hapijs/joi[joi] extension used to validate/parse phone numbers.
Internally it is using Google's library https://github.com/googlei18n/libphonenumber[libphonenmber].
== Requirements
- nodejs >= 4
- npm >= 2
== Install
.Add the dependency to your package.json
npm install joi-phone-validator --save
== Usage === Importing the lib
.Require the lib if using ES5
var phoneValidator = require('joi-phone-validator');
.Import the module if using ES6
import phoneValidator from 'joi-phone-validator'
=== Using the lib
.Validate phone number format
var schema = phoneValidator.phone().validate() var result = Joi.validate('+33123456789', schema) // result.error -> null
// result.value -> '+33123456789'
.Validate phone number is mobile
var schema = phoneValidator.phone().mobile() var result = Joi.validate('+33623456789', schema) // result.error -> null
// result.value -> '+33623456789'
.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
1.0.0
8 years ago