1function validateEmail(email) {
2 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,}))$/;
3 return re.test(String(email).toLowerCase());
4}
5
1function validateEmail(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/* JavaScript: validating email address */
2
3isValidEmail("xyz@abc.com"); // true
4
5function isValidEmail(email) {
6 var emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
7 return !!email && typeof email === 'string'
8 && email.match(emailformat)};
9};
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<!DOCTYPE html>
2<html>
3<head>
4 <title>Email validation</title>
5 <script type="text/javascript">
6 function email_funnction() {
7 var email = document.emailform.email.value;
8 if(email.indexOf('@')<=0){
9 document.getElementById('errormsg').innerHTML="Invalid your Email Address";
10 return false;
11 }
12 if ((email.charAt(email.length-4)!='.') && (email.charAt(email.length-3)!='.')) {
13 document.getElementById('errormsg').innerHTML="Invalid your Email Address";
14 return false;
15 }
16 }
17
18 </script>
19</head>
20<body>
21 <h1>Email Validation in javascript</h1>
22 <span id="errormsg"></span>
23<form name="emailform" onsubmit="return email_funnction()">
24
25 <label>Email</label>
26 <input type="text" name="email" value="">
27 <input type="submit" name="" value="Submit">
28</form>
29</body>
30</html>
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8">
5<title>JavaScript form validation - checking email</title>
6<link rel='stylesheet' href='form-style.css' type='text/css' />
7</head>
8<body onload='document.form1.text1.focus()'>
9<div class="mail">
10<h2>Input an email and Submit</h2>
11<form name="form1" action="#">
12<ul>
13<li><input type='text' name='text1'/></li>
14<li> </li>
15<li class="submit"><input type="submit" name="submit" value="Submit" onclick="ValidateEmail(document.form1.text1)"/></li>
16<li> </li>
17</ul>
18</form>
19</div>
20<script src="email-validation.js"></script>
21</body>
22</html>
23
24