0 votes
1 view
in Web Technology by (47.8k points)

How can an email address be validated in JavaScript?

1 Answer

0 votes
by (107k points)

For validating an email address in JavaScript you can use regular expressions which is the best way.

Below is the code for the same:-

function validateEmail(email) { 

var re = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[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()); 

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...