Validate email address using regex in JavaScript
Taimoor Sattar・
We can define regular expressions to match the patterns in strings. To validate the email address, we can define the regex expression for email validation as below.
function validateEmail (email) {
const 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(String(email).toLowerCase());
};
To test the email address whether it valid or not, console.log
the below command in the terminal.
validateEmail("your@email.com")
Share this Blog
Course
You will learn to build a website that will stand out and accelerate your career. Together, we will develop a subscription website that gives users access to premium content based on their subscription level.
Click to Learn More →