I'm diving into the world of email address specifications and finding it overwhelming! For my website, I'm aiming to import existing email addresses to use as usernames, specifically targeting businesses rather than individual consumers. My main concern is figuring out what a reasonable subset of the email format to accept would be. Ideally, I'd like to keep things simple by only allowing lowercase alphanumeric characters and non-consecutive periods, without any hyphens or special characters. Is this too restrictive? Should I be prepared to handle more complex formats, or do most users not really care about the intricacies of the email spec?
4 Answers
Instead of getting too hung up on validation, focus on sending a confirmation email to verify the email's existence. A basic regex to check the format could be something like `[^@]+@[^@]+` - just make sure there’s one '@' with something before and after. But if companies are importing these emails, validation shouldn't be your biggest worry. Why not allow some flexibility for unusual characters, too?
Have you thought about just letting users choose their username? Many have had the same email for ages and might prefer not to have it enforced as their username.
That's a good idea! I plan to let them set display names freely.
Remember that email specifications exist for a reason. If a user faces issues with their email not working, they might not take it lightly. Businesses will expect adherence to standard formats without bending the rules for your app.
Totally agree! I want to keep it user-friendly while being compliant, but how strict can I really afford to be?
For your case, I would think most users stick to typical formats like `^[a-z0-9-._]+@[a-z0-9-._]+$`. Since it's for businesses, the likelihood of encountering weird email formats is low. You might want to strip out non-alphanumeric characters when forming usernames, and consider allowing users to edit their username later for flexibility. Just remember, some email addresses can use non-Latin characters, so it’s good to have a fallback plan for those situations.
Good catch! I didn’t think about Unicode support. Thanks for the reminder!

I get your point! I'm just cautious about using the email part directly as a username in URLs, which is my main concern.