form validate jquery code example

Example 1: invoking jquery validator

$(document).ready(function () {

    $('#myform').validate({ // initialize the plugin
        // rules & options
    });

    $('#button').click(function() {
        if ($('#myform').valid()) {
            alert('form is valid - not submitted');
        } else {
            alert('form is not valid');
        }
    });

});

Example 2: jquery form validation

function submitFunction(event){
	event.preventDefault();
}
$("#form_id").submit(submitFunction);

Example 3: jquery validate

$("#myform").validate({
  debug: true
});

Example 4: form validation using jquery

<html>
<body>
<h2>Validation of a form</h2>
<form id="form" method="post" action="">
First name:<br>
<input type="text" name="firstname" value="john">
<br>
Last name:<br>
<input type="text" name="lastname" value="Doe">
<br>
Email:<br>
<input type="email" name="u_email" value="[email protected]">
<br>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>