Drupal allows spaces in usernames, is there an easy way to stop this?

Also, where is the documentation on the username specs? What are the min/max lengths and which characters are allowed?

2 Answers 2


The best way to handle this is to implement hook_form_FORM_ID_alter for the user sign up and edit forms and append your own validator to check for spaces in the username field.

As for the length of a username, the minimum is 1 character and the maximum is 60 - as per the db schema.


A quick alternative is using Access rules, in drupal 6 you'll find them at yoursite.com/admin/user/rules for Drupal 7 I believe it was spun of to contrib as User restrictions

All you need to do to disallow spaces in usernames is create a rule like this: % %

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.