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

1.3.2 • Public • Published

yup-phone MIT License npm - yup-phone Tweet yup-phone validator

Build Status Commitizen friendly FOSSA Status Known Vulnerabilities Codacy Badge

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

Install

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

Test

Check validation in Codesandbox

Examples

// See https://repl.it/repls/WiryCleverPatches
import * as yup from 'yup';
// const yup = require("yup");
import "yup-phone";
// require("yup-phone");

// validate any phone number (defaults to India for country)
const phoneSchema = yup.string()
  .phone()
  .required();

(async () => {
  console.log(await phoneSchema.isValid("9876543210")); // → true
})();

// See https://repl.it/repls/SwiftImpossibleCertification
import * as yup from 'yup';
// const yup = require("yup");
import "yup-phone";
// require("yup-phone");

// validate phone number loosely in the given region
const phoneSchema = yup.string()
  .phone("IN")
  .required();

(async () => {
  console.log(await phoneSchema.isValid('+919876543210')); // → true
})();

// See https://repl.it/repls/PartialAlicebluePrediction
import * as yup from 'yup';
// const yup = require("yup");
import "yup-phone";
// require("yup-phone");

// validate phone number strictly in the given region
const phoneSchema = yup.string()
  .phone("IN", true)
  .required();

console.log(phoneSchema.isValidSync("+919876543210")); // → true

// See https://repl.it/repls/UniqueForsakenDownloads
import * as yup from 'yup';
// const yup = require("yup");
import "yup-phone";
// require("yup-phone");

// validate phone number strictly in the given region with custom error message
const phoneSchema = yup.string()
  .phone('IN', true, '${path} is invalid')
  .required();

try {
  phoneSchema.validateSync('+1 345 9490088');
} catch (error) {
  console.log(error.message); // → this is invalid
}

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

Module Sizes

Destination: dist/yup-phone.umd.js
Bundle Size:  544.08 KB
Minified Size:  537.41 KB
Gzipped Size:  107.04 KB 
Destination: dist/yup-phone.umd.min.js
Bundle Size:  508.65 KB
Minified Size:  506.46 KB
Gzipped Size:  105.73 KB 
Destination: dist/yup-phone.esm.js
Bundle Size:  648 B
Minified Size:  646 B
Gzipped Size:  370 B 
Destination: dist/yup-phone.cjs.js
Bundle Size:  1.35 KB
Minified Size:  1.34 KB
Gzipped Size:  662 B 

Contributing

  • Uses Rollup for bundling.
  • Uses npm for package management.
  • Files are minified using closure compiler.
  • Uses jest for testing.
  • Generates CJS, UMD, and ESM builds.
  • Use npm version [major|minor|patch] to version.
  • Use tslint and prettier for code formatting.
  • Uses semantic release for version.
  • Use npx cz to create a standard commit interactively.
$ npm run build # Build for production
$ npm test # Run tests
$ npm publish # Publish npm package (prompts for version)

License

MIT.

FOSSA Status

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.217,029latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.217,029
1.3.1125
1.2.19452
1.2.181
1.2.172
1.2.160
1.2.150
1.2.140
1.2.132
1.2.122,540
1.2.112
1.2.101
1.2.90
1.2.81
1.2.70
1.2.61
1.2.521
1.2.40
1.2.312
1.2.28
1.2.11
1.2.00
1.1.22
1.1.10
1.1.01
1.0.10
1.0.00

Package Sidebar

Install

npm i yup-phone

Weekly Downloads

20,201

Version

1.3.2

License

MIT

Unpacked Size

3.4 MB

Total Files

14

Last publish

Collaborators

  • abhisekp