I've been using Yup and Formik for form validation in React. How can I set validation for input language? I want to a user can (and only can) write in a specific language (change the default language of the keyboard)
const validationSchema = yup.object().shape({
first_name: yup.string().required("Required *"),
last_name: yup.string().required("Required *"),
});
You can use Regex pattern. For example for the English language:
const nameRegex = /^[A-Za-z]+$/;
const validationSchema = yup.object().shape({
first_name: yup.string().matches(nameRegex, "Only English letters").required("Required *"),
last_name: yup.string().matches(nameRegex, "Only English letters").required("Required *"),
});
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