Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific language Yup validation

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 *"),
 });
like image 306
S. Hesam Avatar asked Nov 05 '25 20:11

S. Hesam


1 Answers

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 *"),
 });
like image 123
S. Hesam Avatar answered Nov 08 '25 12:11

S. Hesam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!