jQuery Form Validation being bypassed
Posted
by
user1953681
on Stack Overflow
See other posts from Stack Overflow
or by user1953681
Published on 2013-11-10T07:07:29Z
Indexed on
2013/11/10
9:54 UTC
Read the original article
Hit count: 237
Can someone tell me what is wrong with my jQuery validation? It is not validating my form, rather, just ignoring the code resulting in no check of the inputs.
Form:
<form class="form" accept-charset="UTF-8" action="URL-to-complete-form" method="POST" onsubmit="return validateForm();">
<input class="form-name" type="text" placeholder="Name"></div>
<input class="form-email" type="text"placeholder="Email"></div>
<input style="background-color: #fc8f12;" type="submit" value="Subscribe">
</div>
</form>
Javascript:
function validateForm()
{
// Validate Name
var title = $(".form-name").val();
if (title=="" ||title=="Name" || title==null) { } else {
alert("Please enter a name!");
}
// Validate Email
var email = $(".form-email").val();
if ((/(.+)@(.+){2,}\.(.+){2,}/.test(email)) || email=="" || email=="Email" || email==null) { } else {
alert("Please enter a valid email");
}
return false;
}
Thank you all for your time and help.
© Stack Overflow or respective owner