@thiagodelgado111/yup-phone
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

yup-phone MIT License

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

Usage

import * as yup from 'yup';
import phoneValidationMethod, { YUP_METHOD } from 'yup-phone';

yup.addMethod(yup.string, PHONE_METHOD, phoneValidation);

// validate any phone number (defaults to US)
const phoneSchema = yup
  .string()
  .phone()
  .required();
phoneSchema.isValid('9876543210'); // → true
import * as yup from 'yup';
import phoneValidationMethod, { YUP_METHOD } from 'yup-phone';

// validate phone number loosely in the given region
const phoneSchema = Yup.string()
  .phone('IN')
  .required();
phoneSchema.isValid('+919876543210'); // → true
import * as yup from 'yup';
import phoneValidationMethod, { YUP_METHOD } from '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.
  • Files are minified using closure compiler.
  • Uses jest for testing.
  • Generates CJS, UMD, and ESM builds.
$ npm run build # Build for production
$ npm run test # Run tests

Acknowledgement

This is a fork of https://github.com/abhisekp/yup-phone

License

MIT.

Dependencies (3)

Dev Dependencies (34)

Package Sidebar

Install

npm i @thiagodelgado111/yup-phone

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

3.27 MB

Total Files

14

Last publish

Collaborators

  • thiagodelgado111