• Resolved l1z0b

    (@l1z0b)


    Hi,

    I am using Ultimate Member version 2.6.11 on WordPress version 6.3.1. I am having trouble with my custom username validation code.

    I am trying to validate the username field to make sure that it contains the string “1234”. I am using the following code:

    add_action( 'um_submit_form_errors_hook', function( $args ) {
    	if ( isset( $args['mode'] ) && 'register' === $args['mode'] ) {
    		if ( !str_contains( $args['user_login'], '1234' ) ) {
    			UM()->form()->add_error( 'user_login', __( 'Username must contain the string "1234".', 'ultimate-member' ) );
    		}
    	}
    }, 8, 1 );

    However, this code is not working. I am still able to register users with usernames that do not contain the required string. Can you please help me?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • missveronica

    (@missveronicatv)

    @l1z0b

    You can try this code snippet.

    add_action( 'um_submit_form_errors_hook__registration', function( $submitted_data ) {
    	
        if ( !str_contains( $submitted_data['user_login'], '1234' ) ) {
            UM()->form()->add_error( 'user_login', __( 'Username must contain the string "1234".', 'ultimate-member' ) );
    	}
    }, 999, 1 );
    Thread Starter l1z0b

    (@l1z0b)

    This solved my problem, thank you very much!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom username validation not working’ is closed to new replies.