Skip to content

☎️ Adds a phone number validation check to yup validator using google-libphonenumber

License

Notifications You must be signed in to change notification settings

jaanauati/yup-phone

 
 

Repository files navigation

yup-phone MIT License

Build Status Commitizen friendly semantic-release Greenkeeper badge

Adds a phone number validation check to yup validator using google-libphonenumber which gives accurate validation checks.
Read more here libphonenumber.

Install

# npm install --save yup-phone
$ yarn add yup-phone

Usage

const Yup = require('yup');
require('yup-phone');

// validate any phone number (defaults to India for country)
const phoneSchema = Yup.string().phone().required();
phoneSchema.isValid('9876543210'); // → true
const Yup = require('yup');
require('yup-phone');

// validate phone number loosely in the given region
const phoneSchema = Yup.string().phone('IN').required();
phoneSchema.isValid('+919876543210'); // → true
const Yup = require('yup');
require('yup-phone');

// validate phone number strictly in the given region
const phoneSchema = Yup.string().phone('IN', true).required();
phoneSchema.isValid('+919876543210'); // → true

For more, check yup-phone.test.ts file.

Contributing

  • Uses Rollup for bundling.
  • Uses yarn for package management.
  • Files are minified using closure compiler.
  • Uses jest for testing.
  • Generates CJS, UMD, and ESM builds.
  • Use yarn version --major|--minor|--patch to version.
  • Use tslint and prettier for code formatting.
  • Uses semantic release for version.
  • Use yarn commit to create a standard commit interactively.
$ yarn build # Build for production
$ yarn test # Run tests

License

MIT.

About

☎️ Adds a phone number validation check to yup validator using google-libphonenumber

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 51.8%
  • TypeScript 48.2%