I have the following code
    const SelectSizesDemo = () => {
      const pattern = new RegExp(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
      const errorMsg = "please provide valid email!";
      const [emailArr, setEmailArr] = useState([]);
      const [error, setError] = useState(false);
      return (
        <div>
          <Select
            style={{ width: "90%" }}
            mode="tags"
            onChange={(e) => setEmailArr(e)}
          ></Select>
          {error && errorMsg}
        </div>
      );
    };
I am trying to do the following. The user should input some email, if its email is valid with my pattern then I should add it to my emailArr, if it's not correct then I should show the error message errorMsg, clear from the selected items and not allow the user to add it to the array.
In this code, I successfully can add any string to my array, so I want your help to understand how can I check that string with my pattern.
Please help me to resolve this problem.
Thanks
 
    
 
     
     
     
     
    