• Resolved Awad

    (@awadaljishi)


    Hi,

    I have this code added to woocommerce registration form:

    <?php if ( get_option( 'woocommerce_registration_generate_username' ) === 'no' ) : ?>
    
    				<p class="form-row form-row-wide">
    					<label for="reg_username"><?php _e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label>
    					<input type="text" class="input-text" name="username" id="reg_username" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
    				</p>
    
    			<?php endif; ?>

    And I want to limit the character length for username field. For example, minimum character length is set to “4” and maximum character length is set to “25

    Appreciate your effort.

Viewing 1 replies (of 1 total)
  • Thread Starter Awad

    (@awadaljishi)

    Found a solution,

    You can use the pattern attribute. The required attribute is also needed, otherwise an input field with an empty value will be excluded from constraint validation.

    <input pattern=".{3,}"   required title="3 characters minimum">
    <input pattern=".{5,10}" required title="5 to 10 characters">

    If you want to create the option to use the pattern for “empty, or minimum length”, you could do the following:

    <input pattern=".{0}|.{5,10}" required title="Either 0 OR (5 to 10 chars)">
    <input pattern=".{0}|.{8,}"   required title="Either 0 OR (8 chars minimum)">
Viewing 1 replies (of 1 total)
  • The topic ‘Minimum/Maximum Username Input | Woocommerce’ is closed to new replies.