. How do I know if the email address is valid in JavaScript?

Asked 1 years ago, Updated 1 years ago, 138 views

How do I know if the email address is valid in JavaScript?

email javascript regex validation

2022-09-22 21:59

1 Answers

The best method is to use regular expressions.

function validateEmail(email) {
    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}


2022-09-22 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.