I'm trying to prevent a user from being saved with Rules when he/she tries to use a username that contains a whitespace. I've already read How can I disallow spaces in usernames? and used the User restrictions module to achieve this, but I'd like to use Rules to do some other stuff (e.g. checking that the username doesn't have more than 20 characters).

So, what I'd like to do is showing an error message on the page and keep all the filled in information in the form without saving it. Is it possible to do this?

I agree. It is a far more maintainable solution.
–
J. ReynoldsAug 2 '14 at 17:21

Thanks for your help. Is this code already supposed to work? I've used it in my custom module, but there's no error thrown when a new user is registrated with a space in it's name. I'd also like to prevent this from happening when an existing user edits his/her account.
–
JeroenAug 3 '14 at 13:54

Hello, this should work. Have you cleared the Drupal cache after adding this bit of code?
–
Aneek MukhopadhyayAug 3 '14 at 15:32