Last active
January 11, 2017 09:18
-
-
Save hemraj7171/0657629176c700e714e7a37b5b7f795f to your computer and use it in GitHub Desktop.
Validate WordPress default comment form using jQuery Validation Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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