Skip to main content

validatePhone

Version

Installation​

yarn add @availity/phone

Usage​

validatePhone is a method that can be applied to yup string schemas and is intended to be used with a <Phone /> component.

import * as yup from 'yup';
import '@availity/phone/src/validatePhone';

const laxSchema = yup
.string()
.validatePhone('This phone number is not possible.');
const strictSchema = yup
.string()
.validatePhone('This phone number is invalid.', true, 'US');

laxSchema.isValid('222-222-2222'); // true
strictSchema.isValid('222-222-2222'); // false

Props​

msg?: string​

Optional message to display when validation fails.

strict?: boolean​

Controls whether or not strict phone number validation is used on the component. Defaults to false. Benefits of not defaulting to strict validation.

country?: string​

Default country for parsing national numbers. This is the two letter ISO country code. If no code is provided, the default is 'US'.