Tuesday, 13 August 2013

Common Email validation for more than one forms using jquery

Common Email validation for more than one forms using jquery

i have a form
<form id="Register" method="post" onsubmit="return validateForm()">
<p><label>Your Email</label><input type="text" name="email"/></p>
<p style="margin-left:27%;"><input type="submit" name="submit"
value="Submit" /></p>
</form>
and i use the javascript validation for this form is
function validateForm() {
var x = document.forms["Register"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
return false;
}
}
i have two or more forms
<form id="Login" method="post" >
<p><label>Email</label><input type="text" name="Log_email" /></p>
<p style="margin-left:27%;"><input type="submit" name="submit"
value="Login" /></p>
</form>
<form id="forgot" method="post">
<p><label>Your Email</label><input type="text" name="email"/></p>
<p style="margin-left:27%;"><input type="submit" name="submit"
value="Submit" /></p>
</form>
how can i rewrite the javascript validation commonly for all these forms.

No comments:

Post a Comment