--- email_registration.module	31 Mar 2009 21:32:13 -0000	1.5.2.5
+++ email_registration.module	5 Apr 2009 12:38:56 -0000
@@ -10,6 +10,8 @@ function email_registration_user($op, &$
   switch ($op) {
     case 'insert':
     $namenew = preg_replace('/@.*$/', '', $edit['mail']);
+    // Change any non-word characters to underscores
+    $namenew = preg_replace('/[^a-zA-Z0-9.-]/', '_', $namenew);
     // if username generated from email record already exists, append underscore and number eg:(chris_123)
     if (db_result(db_query("SELECT count(*) FROM {users} WHERE uid <> %d AND LOWER(name) = LOWER('%s')", $account->uid, $namenew)) > 0) {
       // find the next number available to append to the name
