Comment form validation
-
I was looking for a a fix which can show comment error in the comment form below fields. I have found the code below from a website. It works but there I want to add a rule which only allows emails with @gmail.com and allow comments minimum of 50 characters and maximum of 500 characters.
Can somebody help in adding the email and comment rule in the code below plz? If the code is wrong then please guide me with a better code.
Thanks in advance!
function comment_validation_init() { if(is_single() && comments_open() ) { ?> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script> <script type="text/javascript"> jQuery(document).ready(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); } }); }); </script> <?php } } add_action('wp_footer', 'comment_validation_init');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Comment form validation’ is closed to new replies.