PageSourceSearch

https://www.drapersonline.com/wp-content/mu-plugins/mbm-comment//assets/comment-validation.js

js drapersonline.com collected 2026-09-24 08:29:06 UTC 4,081 bytes, 103 lines download raw bytes

1jQuery(document).ready(function($) {
2     
3    var commentField = $('#commentform #comment');
4    var submitButton = $('#commentform #submit');
5
6    // Function to validate comment field
7    function validateComment() {
8
9        if(recaptchaSettings.enable){
10            if (typeof grecaptcha !== 'undefined') {
11                grecaptcha.ready(function() {
12                    grecaptcha.execute(recaptchaSettings.site_key, {action: 'submit'}).then(function(token) {
13                        var recaptchaResponse = document.getElementById('g-recaptcha-response-v3');
14                        recaptchaResponse.value = token;
15                    });
16                });
17            } else {
18                console.error('reCAPTCHA not loaded.');
19            }
20        }
21        // Disable the submit button initially
22        submitButton.prop('disabled', true);
23
24        var comment = commentField.val().trim();
25        var forbiddenPatterns = [
26            'www\\.',
27            'http://',
28            'https://',
29            '\\.com',
30            '\\.co\\.uk',
31            '@',
32            'w w w.',
33            '<.*?>',
34            '\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b' // IP address
35        ];
36        var pattern = new RegExp(forbiddenPatterns.join('|'), 'i');
37
38        // Remove previous error styles and messages
39        $('#comment-error-message').remove();
40        commentField.css({
41            'border': '',
42            'background-color': ''
43        });
44
45        // Check for errors
46        if (pattern.test(comment)) {
47            $('<div id="comment-error-message" style="color: red; margin-bottom: 10px; font-size: 12px;">Comments cannot contain URLs, email addresses and HTML tags.</div>').insertAfter('#comment');
48            commentField.css({
49                'border': '1px solid red',
50                'background-color': '#ffe6e6'
51            }); // Highlight the field with error
52            submitButton.prop('disabled', true);
53       
54        } else {
55            submitButton.prop('disabled', false);
56        }
57    }
58
59    // Validate comment field on input
60    commentField.on('input', validateComment);
61
62    // Validate comment field on form submission
63    $('#commentform').on('submit', function(event) {
64        validateComment();
65        
66        /*if (typeof grecaptcha !== 'undefined') {
67            grecaptcha.ready(function() {
68                grecaptcha.execute(recaptchaSettings.site_key, {action: 'submit'}).then(function(token) {
69                    var recaptchaResponse = document.getElementById('g-recaptcha-response');
70                    recaptchaResponse.value = token;
71                });
72            });
73         } else {
74                console.error('reCAPTCHA not loaded.');
75         }*/
76
77        var comment = commentField.val().trim();
78        if (submitButton.prop('disabled')) {
79            event.preventDefault(); // Prevent form submission if invalid
80        }else if (comment === '') {
81            $('<div id="comment-error-message" style="color: red; margin-bottom: 10px; font-size: 12px;">Comments cannot be empty.</div>').insertAfter('#comment');
82            commentField.css({
83                'border': '1px solid red',
84                'background-color': '#ffe6e6'
85            }); // Highlight the field with error
86            //submitButton.prop('disabled', true);
87            event.preventDefault(); // Prevent form submission if invalid
88            
89        }
90        if(recaptchaSettings.enable){
91            if (typeof grecaptcha !== 'undefined') {
92                grecaptcha.ready(function() {
93                    grecaptcha.execute(recaptchaSettings.site_key, {action: 'submit'}).then(function(token) {
94                        var recaptchaResponse = document.getElementById('g-recaptcha-response-v3');
95                        recaptchaResponse.value = token;
96                    });
97                });
98            } else {
99                console.error('reCAPTCHA not loaded.');
100            }
101        }
102    });
103});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.