0

What I would like to achieve, is to write a protection against people entering an email address in a string. It is important to not only detect valid addresses, but to also built a protection against entries like the following:

my email @ domain dot com
myemail at domain.com
myemail_at_domain_com
myemailatdomaindotcom

etc.

However, things like "@hello" should still be possible or "com-pany".

I'm thinking there should be a list of regular expressions to check against, covering the most known ways of writing an email address (or something that people will understand to be an email address).

This challenge must have been solved a thousand times... :) Isn't there a lib of expressions to check against?

Paul Maclean
  • 631
  • 4
  • 14
  • 30
  • Allowing your users to communicate yet trying to keep them from communicating certain things is a losing battle. You just annoy your user base and force them to be more creative than your regex. Mail me at digitalchris. The service is the mail which is hot. My gmail is currently p.maclean. – Digital Chris Mar 10 '14 at 14:33
  • Why do you need to completely validate an email address? What is the purpose? Just keep it simple and check for one occurrence of "@" and a domain extension at the end of the string. If you're trying to "be smart" and validate before sending an email, don't. It's best to just have your server attempt to send an email and if it fails, that's the user's fault. – tenub Mar 10 '14 at 14:41
  • @tenub, I am not trying to let users fill in a correct email address. I'm trying to stop them from doing so at all ;) The point is that our company offers a mediating service and if smart users put their address in their user name (or any text for that matter), we will be cut out and we might will probably not get our commission. – Paul Maclean Mar 12 '14 at 15:35
  • But, @DigitalChris: I believe you are right. It is fighting a losing battle. We need moderation anyhow, but whatever attempts we can automatically prevent is a gain. – Paul Maclean Mar 12 '14 at 15:36

0 Answers0