{"id":13974959,"date":"2021-01-29T11:25:28","date_gmt":"2021-01-29T11:25:28","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/comment-form-validation-2\/"},"modified":"2021-01-29T16:51:12","modified_gmt":"2021-01-29T16:51:12","slug":"comment-form-validation-2","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/comment-form-validation-2\/","title":{"rendered":"Comment form validation"},"content":{"rendered":"<p>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 <strong>@gmail.com<\/strong> and allow comments <strong>minimum of 50 characters<\/strong> and <strong>maximum of 500 characters. <\/strong><\/p>\n<p>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. <\/p>\n<p>Thanks in advance! <\/p>\n<pre><code>function comment_validation_init() {\n    if(is_single() &amp;&amp; comments_open() ) { ?&gt;        \n    &lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.aspnetcdn.com\/ajax\/jquery.validate\/1.9\/jquery.validate.min.js&quot;&gt;&lt;\/script&gt;\n    &lt;script type=&quot;text\/javascript&quot;&gt;\n    jQuery(document).ready(function($) {\n    $(&#039;#commentform&#039;).validate({\n\n    rules: {\n      author: {\n        required: true,\n        minlength: 2\n      },\n\n      email: {\n        required: true,\n        email: true\n      },\n\n      comment: {\n        required: true,\n        minlength: 20\n      }\n    },\n\n    messages: {\n      author: &quot;Please fill the required field&quot;,\n      email: &quot;Please enter a valid email address.&quot;,\n      comment: &quot;Please fill the required field&quot;\n    },\n\n    errorElement: &quot;div&quot;,\n    errorPlacement: function(error, element) {\n      element.after(error);\n    }\n\n    });\n    });\n    &lt;\/script&gt;\n    &lt;?php\n    }\n    }\n    add_action(&#039;wp_footer&#039;, &#039;comment_validation_init&#039;);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13974959","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13974959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13974959\/revisions"}],"predecessor-version":[{"id":13976694,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13974959\/revisions\/13976694"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13974959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}