yup number validation code example
Example 1: yup phone validation
const phoneRegExp = /^((\\+[1-9]{1,4}[ \\-]*)|(\\([0-9]{2,3}\\)[ \\-]*)|([0-9]{2,4})[ \\-]*)*?[0-9]{3,4}?[ \\-]*[0-9]{3,4}?$/
phoneNumber: Yup.string().matches(phoneRegExp, 'Phone number is not valid')
Example 2: yup only characters regex validation react
yup.string()
.required("Please enter the required field")
.matches(/^[aA-zZ\s]+$/, "Only alphabets are allowed for this field ")
Example 3: yup number validation custom message
numberFiled: Yup.number()
.typeError('you must specify a number')
.min(0, 'Min value 0.')
.max(30, 'Max value 30.')
Example 4: yup oneOf
let schema = yup.mixed().oneOf(['jimmy', 42]);
await schema.isValid(42);
await schema.isValid('jimmy');
await schema.isValid(new Date());