How to add custom regex validation to WPForms password field

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?

Topic validation regex forms Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.