Reputation: 816
I want to allow only fixed length digits as username for my woocommerce store. Is that possible to do?
For that I have edited my validate_username
function in user.php
. I have used below code but it's not working.
$valid = ( preg_match( "/\d{10,10}/", $username ) && ! empty( $sanitized ) );
I am very new for woocommerce as well for wordpress. Can anyone please help me?
Upvotes: 0
Views: 666
Reputation: 777
I'm not familiar with wordpress or woocommerce, but in normal php you can just do something like this if (strlen($username) < 11)
or if (strlen($username) <= 10)
Upvotes: 1
Reputation: 2401
Use this
^\d{10}$
Explanation
^
asserts position at start of the string
\d{10}
matches 10 digits
$
asserts position at end of the string
Upvotes: 2