• Stars
    star
    236
  • Rank 169,856 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

yup-phone MIT License npm - yup-phone Tweet yup-phone validator Buy Me A Coffee

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

More Repositories

1

Practice-Modern-JavaScript

💎 🎀 A boilerplate to setup and Practice Modern JavaScript
JavaScript
12
star
2

gitter-archive-cli

💬 💾 Gitter Chat room message downloader
JavaScript
6
star
3

rate-limiter-api

⏰ ⌚ A simple library to easily manage rate limits of APIs without any hassles.
JavaScript
5
star
4

cyclic-next

🔮 ➿ Get the cyclic next integer number.
JavaScript
5
star
5

blogapp

Blog App
JavaScript
3
star
6

crawl-amazon

TypeScript
2
star
7

rust_compile_run

A Rust CLI tool to compile, run, and optionally delete Rust executables with additional features like file watching and notifications.
Rust
2
star
8

BeatBox

Music Beat Box
CSS
2
star
9

Single-Linked-List

Single-Linked-List
Go
1
star
10

xlsx

Test XLSX file parsing
JavaScript
1
star
11

refactored

JavaScript
1
star
12

react-bootcamp

Free React bootcamp demo project
JavaScript
1
star
13

go-builder-pattern

Builder Pattern
Go
1
star
14

Single-Linked-List-Expertifie

Go
1
star
15

codesandbox-remix

Remix template for CodeSandbox Projects
TypeScript
1
star
16

ds-and-algos

Data Structures and Algorithms in Javascript
TypeScript
1
star
17

DeferLoader

(Coming Soon) A simple and basic Javascript library for loading scripts and stylesheets later with dependency
1
star
18

demo-bull-queue

Demo for bull queue manager
JavaScript
1
star
19

FCC-Project-TicTacToe

🔰 🎲 FreeCodeCamp Tic Tac Toe Project
JavaScript
1
star
20

env-vars

A script to download and store all environment variables from web and store in database
JavaScript
1
star
21

REPL-CLI

REPL Server CLI demo with Command Completion
TypeScript
1
star
22

getir

TypeScript
1
star
23

abhisekp.github.io

My Personal Page
HTML
1
star
24

learn-go

Go
1
star
25

jest-pub-sub

Test Redis PubSub using Jest testing framework
JavaScript
1
star
26

vite-react-ts

TypeScript
1
star
27

buble-jest-flow

Custom jest transformer to remove flow type annotations using buble
JavaScript
1
star
28

conf42-golang-2023-building-cli-app

Building CLI App in Go: Generating Randomized Data
Go
1
star
29

findMinMaxSubArray

Find the largest/minimum combination of 3 contiguous numbers with maximum sum in an array
JavaScript
1
star
30

doubly-linked-circular-list

Doubly Linked Circular List data structure implementation
JavaScript
1
star
31

react-router-demo

React router demo
JavaScript
1
star
32

empty-dir

Empty directory
1
star
33

iamwayforward

Static website content for #iamwayforward
JavaScript
1
star
34

FCC-Project-Timestamp

🔰 ⏲️ FreeCodeCamp project on Timestamp Microservice
1
star
35

lexical-playground

TypeScript
1
star
36

inquirer-npm-name

Helper function using inquirer to validate a value provided in a prompt does not exist as an npm package.
JavaScript
1
star