I have a little problem concerning jquery and email validation. I am using an email typed input box to retrieve user's entered email address (html5) but it doesn't work on IE, I now would like to add in a simple jquery function to validate input email address before submitting the form. Here is what I have done.
function IsValidEmail(email)
{
var eReg=/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return eReg.test(email);
}
$(document).ready(function()
{
var em=$('#email').val();
if(!IsValidEmail(em))
{
$('#e-valid').css('color','red');
$('#e-valid').html("Email is invalid.Please enter a valid address");
}
}
);
and here is the form
<form method="POST" action="doit" id="stuff">
<table>
<tr>
<td width="175px"><label for="email">Your email address</label></td>
<td><input type="email" name="email" id="email" size="35"/><span id="e-valid"> </span></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Send" /></td>
</tr>
</table>
</form>
However, nothing is being shown when I entered an invalid email address in the input box. I am thankful for any help. Thank you.