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};
1function ValidateEmail(inputText)
2{
3var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
4if(inputText.value.match(mailformat))
5{
6document.form1.text1.focus();
7return true;
8}
9else
10{
11alert("You have entered an invalid email address!");
12document.form1.text1.focus();
13return false;
14}
15}
16
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>
1function ValidateEmail(inputText)
2{
3var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
4if(inputText.value.match(mailformat))
5{
6document.form1.text1.focus();
7return true;
8}
9else
10{
11alert("You have entered an invalid email address!");
12document.form1.text1.focus();
13return false;
14}
15}