I'm trying to use jQuery validation plugin to validate a few form fields by using custom add.method, and I need some help with it. Here is my html form.
<form method="post" action="<?=$PHP_SELF?>" name="sf" id="sf">
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name" /><br />
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" id="email" /><br />
</p>
</form>
Basically I'm trying a very basic rule to check if the Name field is not empty. I'm trying following, Please let me know if it is correct?
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("name",function(value,element){
return this.optional(element) || (i.test(value) > 0);
},"Name is required");
$("#sf").validate({
rules: {
name: true,
},
});
});
</script>
I want to display the name error message in front of the Name field in the form. How I can do that? Thanks for any help.