0

I'm using WPForms Pro and I'd like to add custom requirements to the password field on a form.

I know that the password field has a password strength requirement setting, but I have specific rules I'd like to enforce, which are:

  • Between 12 and 32 characters
  • At least 1 number
  • At least 1 capital letter
  • At least 1 special character

I came up with the following regex for this: ^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,32}$

and wrote to WPForms support, who told me that they can only go as far as giving me a code snippet to enforce a minimum length:

/**
 * Require number of characters allowed for an input field
 * Apply the class "wpf-char-require" to the field to enable.
 *
 */
function wpf_dev_char_require() {
    ?>
    <script type="text/javascript">
        jQuery(function($){
            $('.wpf-char-require input').attr('minlength',4); // Change number to character requirement (input fields)
        });
    </script>
    <?php
}
add_action( 'wpforms_wp_footer', 'wpf_dev_char_require' );

(I'd add the wpf-char-require class to the field I want to validate).

How can I modify this to validate using my regex instead of the rule they've given me?

4
  • have you contacted WPForms Pro support? 3rd party plugin/theme dev support questions are offtopic here and not in this stacks scope
    – Tom J Nowell
    Apr 21, 2022 at 13:12
  • @TomJNowell I have, I mentioned that in my post above. The snippet I have is from them. The reason I asked here is because they’re unwilling to support further, and I thought that this is more of a generic question about field validation that could pertain to any form, created with/without a plugin.
    – Sidewinder
    Apr 21, 2022 at 13:17
  • if you know how to change the minimum length then you have everything you need to replace that line with code that enforces a regex, you don't need WPForms or WordPress help to do the regular expression part, any javascript developer could answer that. Your question can be rephrased to completely remove WordPress and WP Forms as "Given an input html goes here, how would I apply a regex validation with jQuery?". That question could be asked on stackoverflow and reach a much larger number of people
    – Tom J Nowell
    Apr 21, 2022 at 13:35
  • Note thought that if PHP changes are needed to make WP Forms Pro enforce the validation then that is something you can't ask for help with here, even if their support routes say they can't help you. 3rd party plugin dev support questions are offtopic, even if their support routes refuse to help you
    – Tom J Nowell
    Apr 21, 2022 at 13:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.