1function checkEmail() {
2
3 var email = document.getElementById('txtEmail');
4 var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
5
6 if (!filter.test(email.value)) {
7 alert('Please provide a valid email address');
8 email.focus;
9 return false;
10 }
11}
12
13- Call the function on Email textbox
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