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.
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 );