1function isValidEmail(email) {
2 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,}))$/;
3 return re.test(String(email).toLowerCase());
4}
1/* Answer to: "email regex javascript" */
2
3ValidateEmail("icecream123@yahoo.com"); // Must be a string
4
5function ValidateEmail(email) {
6 var emailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(String(email).toLowerCase());
7 if (email.match(emailformat)) {
8 alert("Nice Email!")
9 return true;
10 };
11 alert("That's not an email?!")
12 return (false);
13};
1/// if you want create your regular expression then you can follow this site
2/////https://regex101.com///////
3<!DOCTYPE html>
4<html>
5<head>
6 <title></title>
7</head>
8<body>
9<form method="post" action="">
10 Email:<input type="text" id="email" onkeyup="validation()">
11 </form>
12</body>
13<script type="text/javascript">
14 function validation(){
15 var email=document.getElementById("email").value;///get id with value
16 var emailpattern=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;////Regular expression
17 if(emailpattern.test(email))
18 {
19 document.getElementById("email").style.backgroundColor='yellow';
20 }
21 else
22 {
23 document.getElementById("email").style.backgroundColor='red'; }
24 }
25
26</script>
27</html>