PageSourceSearch

https://www.hohengoeft.fr/wp-content/plugins/wp-user-frontend-pro/…/frontend-twitter-validation.js?ver=4.3.13

js hohengoeft.fr collected 2026-10-02 20:05:09 UTC 2,969 bytes, 80 lines download raw bytes

1(function($) {
2    'use strict';
3
4    $(document).ready(function() {
5        // Twitter username validation pattern (username only)
6        const twitterUsernamePattern = /^[a-zA-Z][a-zA-Z0-9_]{3,14}$/;
7
8        // Validate Twitter field on blur and input
9        $(document).on('blur input', 'input[data-type="text"][name*="twitter"]', function() {
10            const $input = $(this);
11            let value = $input.val().trim();
12            const $wrapper = $input.closest('.wpuf-fields');
13
14            // Remove any existing error messages
15            $input.removeClass('wpuf-error wpuf-valid');
16            $wrapper.find('.wpuf-error-msg').remove();
17
18            // Remove @ symbol if user added it
19            if (value.startsWith('@')) {
20                value = value.substring(1);
21                $input.val(value);
22            }
23
24            if (!value) {
25                return; // Empty is valid (handled by required field validation)
26            }
27
28            let isValid = twitterUsernamePattern.test(value);
29            let errorMessage = 'Please enter a valid X (Twitter) username (4-15 characters, must start with a letter).';
30
31            if (isValid) {
32                $input.addClass('wpuf-valid');
33            } else {
34                $input.addClass('wpuf-error');
35                $wrapper.append('<span class="wpuf-error-msg wpuf-twitter-error">' + errorMessage + '</span>');
36            }
37        });
38
39        // Handle form submission
40        $(document).on('submit', '.wpuf-form-add, .wpuf-profile-form', function(e) {
41            let hasError = false;
42
43            $(this).find('input[data-type="text"][name*="twitter"]').each(function() {
44                const $input = $(this);
45                let value = $input.val().trim();
46                const isRequired = $input.data('required') === 'yes';
47
48                // Remove @ symbol if present
49                if (value.startsWith('@')) {
50                    value = value.substring(1);
51                    $input.val(value);
52                }
53
54                if (!value && !isRequired) {
55                    return; // Skip validation for empty non-required fields
56                }
57
58                if (value) {
59                    let isValid = twitterUsernamePattern.test(value);
60
61                    if (!isValid) {
62                        hasError = true;
63                        $input.trigger('blur'); // Trigger blur to show error
64                    }
65                }
66            });
67
68            if (hasError) {
69                e.preventDefault();
70                // Scroll to first error
71                const $firstError = $('.wpuf-error:first');
72                if ($firstError.length) {
73                    $('html, body').animate({
74                        scrollTop: $firstError.offset().top - 100
75                    }, 500);
76                }
77            }
78        });
79    });
80})(jQuery);

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.