• Resolved rando390

    (@rando390)


    I’m trying to use the um_validation_safe_username_regex filter (see below) to limit registration usernames only to alphanumeric characters. I’m enacting it as a Snippet and activating it. But Ultimate Member is allowing users to continue registering with the dashes, spaces, underscores, etc.

    function um_custom_validation_safe_username( $regex_safe ) {
    $regex_safe = '/^[A-Za-z0-9]+$/';
    return $regex_safe;
    }
    add_filter( 'um_validation_safe_username_regex', 'um_custom_validation_safe_username', 10, 1 );

    Does this filter only add additional characters to allow, or can it be used to further restrict? I don’t understand why it’s not working.

    • This topic was modified 1 year, 5 months ago by rando390.
Viewing 1 replies (of 1 total)
  • Thread Starter rando390

    (@rando390)

    Never mind, turns out I’m not so bright. I misunderstood the filter as providing a list of characters it ALLOWED rather than DISALLOWED.

    For anyone in the future who can benefit from this, here is the working code.

    function my_custom_username_validation_regex( $default_regex ) {
    // This regex disallows any character that is not alphanumeric.
    $non_alphanumeric_regex = '/[^a-z0-9]/i';
    return $non_alphanumeric_regex;
    }
    add_filter( 'um_validation_safe_username_regex', 'my_custom_username_validation_regex', 10, 1 );

    • This reply was modified 1 year, 5 months ago by rando390.
Viewing 1 replies (of 1 total)
  • The topic ‘um_validation_safe_username_regex not allowing me to restrict additional chars?’ is closed to new replies.