Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to strip spaces from email addresses?

I sometimes have messages from users saying that they can't log in. Most often I have found it's because they inadvertently added a space either before or after their email.

Is it a good idea to automatically strip spaces from emails on log in or on any form entry?

$email =~ s/\s//g; #strip all spaces out
like image 986
Colin R. Turner Avatar asked Dec 28 '25 19:12

Colin R. Turner


1 Answers

This topic will answer most of your questions. I'm putting bellow a brief summary:

  • Emails/Usernames: I agree with Rajwanshi, as spaces are not a valid character in emails, there is no harm in removing them. In the company I'm working for, we had the same problem that you are describing and removing all spaces turned out to be a good solution.

  • Passwords: As they say here, you shouldn't trim or modify them in any way. Just hash them as is.

  • Other text inputs: I would say to act depending on the context. But if you decide to trim, I would advise to do it on submit as it would not bring a good user experience to use online validation and bother users with an ending space.

Hope it will help you

like image 81
SofienM Avatar answered Dec 31 '25 11:12

SofienM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!