Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yup-phone

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yup-phone

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

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 14 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc