joi-international-phone

Allows you to do joi.internationalPhone()

Usage no npm install needed!

<script type="module">
  import joiInternationalPhone from 'https://cdn.skypack.dev/joi-international-phone';
</script>

README

What

Allows you to do joi.internationalPhone()

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 joi = require('joi')
    .extend(require('joi-international-phone'));

const schema = joi.object({
    phone: joi.internationalPhone()
});

schema.validate('+ 55 55 99730 0000'); 
// {
//    value: '+55 55 99730-0000',
//    error: null
// }

schema.validate('not a phone');
// {
//    value: 'not a phone',
//    error: 'The string supplied did not seem to be a phone number'
// }