How to make .val().toLowerCase() work properly?
I am having a hard time trying to show errors with jquery. I want to
confirm a email input by the user. Basically, if the user doesn't fill in
the fields correctly, I want the error to show.
I want the user to fill in both fields with the same input text. If the
user doesn't, I want to show the error "emails are not the same" under the
"email_confirm" input. If they are, I want to hide this error.
Here is a fiddle I made: http://jsfiddle.net/5ZjwW/1/
This is my jquery code:
$("#email").blur(function ()
{
if ($("#email").val() == "")
{
$("#err1_email").removeClass("hidden");
$("#err2_email").addClass("hidden");
}
else
{
$("#err1_email").addClass("hidden");
if (!emailregex.test($('#email').val()))
{
$("#err2_email").removeClass("hidden");
}
else
{
$("#err2_email").addClass("hidden");
}
}
})
$("#email_confirm").blur(function ()
{
if ($("#email_confirm").val() == "")
{
$("#err1_confirmemail").removeClass("hidden");
}
else
{
$("#err1_confirmemail").addClass("hidden");
if ($("email_confirm").val().toLowerCase() !=
$("email").val().toLowerCase())
{
$("#err2_confirmemail").removeClass("hidden");
}
else
{
$("#err2_confirmemail").addClass("hidden");
}
}
})
Thank you very much.
No comments:
Post a Comment