How can I compel alphanumeric entries for username textbox on woocommerce registration form

admin2025-06-03  3

I am having a bit of a challenge with Woocommerce registration form. Currently, users are able to register using all numeric characters as their usernames. I can't think of a way to enforce that they use only alphanumeric combinations. Not only numbers. I can't seem to find any answers anywhere.

I am having a bit of a challenge with Woocommerce registration form. Currently, users are able to register using all numeric characters as their usernames. I can't think of a way to enforce that they use only alphanumeric combinations. Not only numbers. I can't seem to find any answers anywhere.

Share Improve this question asked Feb 4, 2019 at 11:31 unkind_sauce1unkind_sauce1 1032 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the woocommerce_registration_errors hook to validate the username & set an error if your conditions aren't met - WooCommerce will bail and pass the error back to the UI for the user:

add_filter( 'woocommerce_registration_errors', function ( WP_Error $errors, $username ) {
    if ( ! preg_match( '/[a-z]/i', $username ) ) {
        $errors->add( 'username', 'Username must contain alphabetic characters.' );
    }

    return $errors;
}, 10, 2 );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748944306a315038.html

最新回复(0)