Adds a phone number validation check to yup validator using google-libphonenumber which gives accurate validation checks.
Read more here libphonenumber.
# npm install --save yup-phone
$ yarn add yup-phone
import * as Yup from "yup";
import "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
})();
import * as Yup from "yup";
import "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
})();
import * as Yup from "yup";
import "yup-phone";
// validate phone number strictly in the given region
const phoneSchema = Yup.string()
.phone("IN", true)
.required();
console.log(phoneSchema.isValidSync("+919876543210")); // → true
For more, check yup-phone.test.ts file.
Destination: dist/yup-phone.umd.js
Bundle Size: 530.02 KB
Minified Size: 522.95 KB
Gzipped Size: 103.4 KB
Destination: dist/yup-phone.umd.min.js
Bundle Size: 503.58 KB
Minified Size: 501.25 KB
Gzipped Size: 102.53 KB
Destination: dist/yup-phone.esm.js
Bundle Size: 602 B
Minified Size: 603 B
Gzipped Size: 349 B
Destination: dist/yup-phone.cjs.js
Bundle Size: 902 B
Minified Size: 900 B
Gzipped Size: 474 B
- 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
$ yarn publish # Publish npm package (prompts for version)
MIT.