Skip to content

Instantly share code, notes, and snippets.

@hemraj7171
Last active January 11, 2017 09:18
Show Gist options
  • Save hemraj7171/0657629176c700e714e7a37b5b7f795f to your computer and use it in GitHub Desktop.
Save hemraj7171/0657629176c700e714e7a37b5b7f795f to your computer and use it in GitHub Desktop.
Validate WordPress default comment form using jQuery Validation Plugin
// Step 1 enqueue jQuery Validation Plugin (http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.js) on function.php
// Step 2 enqueue jQuery this js file
// enjoy
jQuery(function($) {
$('#commentform').validate({
rules: {
author: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
comment: {
required: true,
minlength: 20
}
},
messages: {
author: "Please fill the required field",
email: "Please enter a valid email address.",
comment: "Please fill the required field"
},
errorElement: "div",
errorPlacement: function(error, element) {
element.after(error);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment