Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Information website that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,195 questions

16,607 answers

573 users

How to validate email address with regular expression in JavaScript

2 Answers

0 votes
function mail_valid(email) {
    var re = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
     
    return re.test(String(email));
}
  
document.write(mail_valid("a@email") ? "valid" : "not valid" + "<br />");
  
document.write(mail_valid("a@email.com") ? "valid" : "not valid");
  
  
/*
run:
      
not valid
valid
      
*/

 




answered Sep 23, 2019 by avibootz
edited Sep 23, 2019 by avibootz
0 votes
function mail_valid(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(String(email));
}
  
document.write(mail_valid("a@email") ? "valid" : "not valid" + "<br />");
  
document.write(mail_valid("a@email.com") ? "valid" : "not valid");
  
  
/*
run:
      
not valid
valid
      
*/

 




answered Sep 23, 2019 by avibootz
edited Sep 23, 2019 by avibootz
...