How can I set minimum characters limit before @ symbol in React Native


This is how I am setting errors in my react native registration page. The issue is that it is checking the whole email length but I need to impose character limit of 3 before the @ symbol. What is the best way to do this?

I am using Native Base as my UI kit

  const validate = () => {
    let errors = {};
    if (!formData.firstName) errors.firstName = "First name is required";
    if (!formData.lastName) errors.lastName = "Last name is required";
    if (! = "Email is required";
    if ( && < 3) = "Email is must be 3 characters";
    if (!formData.password) errors.password = "Password is required";
    if (!formData.confirmPassword)
      errors.confirmPassword = "Confirm password is required";
    if (formData.password !== formData.confirmPassword)
      errors.confirmPassword = "Passwords do not match";
    return Object.keys(errors).length === 0;

>Solution :

You could use the split function as follows.

if ( &&'@') &&'@')[0].length < 3)

Leave a ReplyCancel reply