• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Requiring both numbers and letters in a text field

Requiring both numbers and letters in a text field 2 days 6 hours ago #44109

  • a2zcs
  • a2zcs's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
Hi,
Trying to setup a text field that requires the submission of a "password", if you will, that requires the use of both letters and numbers. How can this be done? Can it be done?
The administrator has disabled public write access.

Requiring both numbers and letters in a text field 1 day 19 hours ago #44110

  • dragos
  • dragos's Avatar
  • OFFLINE
  • Administrator
  • Posts: 654
  • Thank you received: 121
You can try using the 'Letters and numbers' validation rule, further info here.
The administrator has disabled public write access.

Requiring both numbers and letters in a text field 1 day 14 hours ago #44111

  • a2zcs
  • a2zcs's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
Hi, That seems to allow the use of either numbers or letters, but does not require them. Need to require they use BOTH numbers and letters.
The administrator has disabled public write access.

Requiring both numbers and letters in a text field 17 hours 14 minutes ago #44114

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 262
  • Thank you received: 70
Try this bit of javascript in the appropriate sectin of your form
document.addEventListener('DOMContentLoaded', function() {
    // ⚠️ CHANGE 'password' BELOW to match your actual RSForm field name
    // Example: if your field is called 'access_code', use: '[name="form[access_code]"]'
    var passwordField = document.querySelector('[name="form[password]"]');
 
    if (passwordField) {
        // Function to check validity and show messages
        function checkPassword() {
            var passwordValue = passwordField.value.trim();
            // Regex: at least one letter, one number, min 8 chars, only letters & numbers
            var passwordPattern = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
 
            // Remove previous message if any
            var oldMessage = document.querySelector('#rsform_error_password');
            if (oldMessage) oldMessage.remove();
 
            var messageSpan = document.createElement('span');
            messageSpan.id = 'rsform_error_password';
 
            if (passwordValue === '') {
                // Field empty, clear styling
                passwordField.classList.remove('valid', 'invalid');
                return false;
            } else if (!passwordPattern.test(passwordValue)) {
                // Invalid password
                messageSpan.className = 'formError';
                messageSpan.textContent = 'Password must include letters and numbers (min 8 characters).';
                passwordField.classList.remove('valid');
                passwordField.classList.add('invalid');
            } else {
                // Valid password
                messageSpan.className = 'formSuccess';
                messageSpan.textContent = 'Password looks good!';
                passwordField.classList.remove('invalid');
                passwordField.classList.add('valid');
            }
 
            // Insert message after the field
            passwordField.parentNode.insertBefore(messageSpan, passwordField.nextSibling);
        }
 
        // Events: live typing and leaving field
        passwordField.addEventListener('keyup', checkPassword);
        passwordField.addEventListener('blur', checkPassword);
 
        // Also validate on form submission
        var form = passwordField.closest('form');
        if (form) {
            form.addEventListener('submit', function(e) {
                var passwordValue = passwordField.value.trim();
                var passwordPattern = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
 
                if (!passwordPattern.test(passwordValue)) {
                    checkPassword(); // Show message if invalid
                    passwordField.focus();
                    e.preventDefault(); // Stop submission
                    return false;
                }
            });
        }
    }
});

Made it so that you get Instant feedback while typing and on blur. Red/green message and pevents form submission if the password is invalid.
Also you'll see a comment to show where you need to change the 'password' field name I've used to match your own RSForm field name.

Now in your 'password' field under validation use Regex and put this in the field

^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$
This sets the minimum length at 8 and requires letters and numbers
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 17 hours 5 minutes ago by iceferret. Reason: added info
The administrator has disabled public write access.
The following user(s) said Thank You: gregs
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!