Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Email Validation using useEffect and RegEx

i can’t make the syntax below do what I expected it to.
When I go to my app and type in the input an email address that does meet the criteria I defined with regex, I still get the error message "Not a valid email address".
Does anyone have any idea what’s wrong with my code? Thank you!

enter image description here

const [emailSignUpErrorMessage, setEmailSignUpErrorMessage] = useState("");

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

I think you’re using match() method incorrectly

You should pass regex inside like email.match(regex)

if (email.match(<your_regex>)) {
// Don't show validation error
} else {
// Show validation error
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading