Trying to validate a phone number field in Formik using Yup validation schema, but when i use Yup.string().matches(/^[0-9]*$/g, 'This is not a number') it consistently alternates between valid and invalid on each change event.
phone: Yup.string()
.trim()
.matches(/^[0-9]*$/g, 'This is not a number')
}),
input field is of type tel. <Field type="tel" id="phone" name="phone" />
Ok, appears i could have been my RegEx after all that was causing this strange behavior.
/^[0-9]*$/g /^[\d]*$/g /^\d+$/ <-- This solved the problem.My regEx knowledge is limited so i would be happy if somebody could tell me why the two first regEx codes caused the alternating state of validation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With