Advertisement
728x90
You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.
javascript
1function validateEmail(email) {
2 var re =
3 /^(([^<>()\[\]\\.,;:\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,}))$/;
4 return re.test(String(email).toLowerCase());
5 }The above regular expression accepts unicode characters.
Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 38
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
122of476