I suddenly realized that username can be any character after seeing someone just made his or her account in Japanese characters. I don't really have a problem with that but just would like to let them register only with alphabetical characters to keep the things tidy. Is there anyway to do this?


Check out the Custom Username Validation module, it seems like it should do exactly what you like.

If not, (In Drupal 6) you can set up "Access Rules" in the administration pages. Set up multiple access rules to deny usernames that contain undesired symbols. Access Rules Docs. Unfortunately that would take a lot of time to deny all non-alphabetical characters.

Finally, you could also create a custom module and use hook_form_alter() (or hook_form_FORM_ID_alter()) to change the validation on the username field. Here's a related question on SO: Hook into Drupal registration and validate user info against business logic

  • Thanks I ended up using Custom Username Validation module with some regular expression. it's perfect and easy. – chinita7 Feb 22 '12 at 15:39
  • Access Rules were removed in Drupal 7. Instead, please use the [User Restrictions][3] module.drupal.org/project/user_restrictions – forest Oct 23 '12 at 19:02
  • Thanks. The question was actually tagged Drupal 6, but it might be helpful to some others who are using Drupal 7 – Laxman13 Oct 24 '12 at 12:57

Using hook_form_alter

You can do like this,

function hook_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_register'){
    $form['#validate'][] = 'user_name_validate';

function user_name_validate($form, &$form_state) {
  $name = $form_state['values']['name'];
  if(preg_match('/[^A-Za-z]/', $name)) {
    form_set_error('name', 'username contains non alphapetic');

In addition to the module or hook_form_alter() you can also use the username originality AJAX check module to show a message to your user before they submit the form.

I was able to modify the code in that module to do my custom validation - I don't like special characters in usernames either ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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