Multiple required conditions of an input with .includes() method

Viewed 14

I'm making validation of an email input in my React App, but I want that input should have both @ and .(dot) while submitting the form. I tried the .some() method but if only one condition is true then it will return true but I want both:

const emailValidation = ["@", "."];
<input
    type="text"
    placeholder="Email"
    value={email}
    onChange={(e) => setEmail(e.target.value)}
    onBlur={(e) => {
        setIsEmailValid(
            emailValidation.some((el) => e.target.value.includes(el))
        );
    }}
/>
1 Answers

<input
     type="text"
     placeholder="Email"
     value={email}
     onChange={(e) => setEmail(e.target.value)}
     onBlur={(e) => {
     setIsEmailValid(
     emailValidation.every((el) => e.target.value.includes(el)));  }}
     />

Here you just need to use every() method instead of some()

Related