Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
var x = document.getElementById("<%= txtEmailAddress.ClientID%>").value;
            var atpos = x.indexOf("@");
            var dotpos = x.lastIndexOf(".");
            var substr = x.substring(atpos+1, dotpos);
          
            if ((atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length)||(substr!="gmail")) {
                document.getElementById("<%= txtEmailAddress.ClientID%>").value = "";
                document.getElementById("<%= lblEmailErrMsg.ClientID%>").innerHTML = "Invalid Email";
                
                return false;
            }
            else {
                document.getElementById("<%= lblEmailErrMsg.ClientID%>").innerHTML = "";
            }
Posted
Updated 31-Jul-14 22:41pm
v2
Comments
Nirav Prabtani 1-Aug-14 3:53am    
what is an isuue?

try this.. :)

JavaScript
function ValidateEmail(inputText)  
{  
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
if(inputText.value.match(mailformat))  
{  
document.form1.text1.focus();  
return true;  
}  
else  
{  
alert("You have entered an invalid email address!");  
document.form1.text1.focus();  
return false;  
}  
}  


HTML

HTML
<html lang="en">  
<head>  
<meta charset="utf-8">  
<title>JavaScript form validation - checking email</title>  
<link rel="stylesheet" href="form-style.css" type="text/css" />        
</head>  
<body onload='document.form1.text1.focus()'>  
<div class="mail">  
<h2>Input an email and Submit</h2>  
<form name="form1" action="#">   
<ul>  
<li><input type='text' name='text1'/></li>  
<li> </li>  
<li class="submit"><input type="submit" name="submit" value="Submit" onclick="ValidateEmail(document.form1.text1)"/></li>  
<li> </li>  
</ul>  
</form>  
</div>  
<script src="email-validation.js"></script>  
</body>  
</html>  


Reference.. :)

JavaScript : HTML Form - email validation[^]
 
Share this answer
 
Well...it's pretty poor.
What if I enter
me@gmail.my.house@home
Or similar?
Is that valid?
Because it passes your tests!

Start with something like this: Email Validation in JavaScript[^] instead of a hack'n'slash job on the W3Schools example you got from here: http://www.w3schools.com/js/js_form_validation.asp[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900