Live data from Hacker News

Perfect email regex finally found

fightingforalostcause.net

101–110 of 118 posts

Re: Perfect email regex finally found

#101
Email validation is user input validation; you are protecting the user from some cases of erronous input, and yourself from stuff that doesn't even look like an email.

I find these large catch-all email regexps silly for two reasons:

1. They are hard to write, hard to understand, and hard to maintain.

2. Most importantly, they are difficult to understand for users. "You entered an invalid email". Now what? the user asks.

This is why e-mail validation should be done in steps. Here is some Rails pseudocode:

  validates_format_of :email,
    :with => /@/,
    :message => "Needs to contain an @."
  
  validates_format_of :email,
    :with => /\.[^\.]+$/,
    :message => "Has to end with .com, .org, .net, etc."
  
  validates_format_of :email,
    :with => /^.+@/,
    :message => "Must have an address before the @"
  
  validates_format_of :email,
    :with => /^[^@]+@[^@]+$/,
    :message => "Must be of the format 'something@something.xxx'"
Much easier to write, much easier to maintain, and much better error messages to the users.

Re: Perfect email regex finally found

#103
post #39

Earlier quoted context omitted.

I also do simple email verification: 1) Send an email to the address. 2) If it succeeds, the address was valid.

In which you are assuming you will receive a proper bounce, which is not warranted. Checking bounces is something you can do in addition to checking whether the user didn't screw up his email address.

If a person clicks on a confirmation link, then the email got through OK.

Re: Perfect email regex finally found

#104
post #76
post #63

Earlier quoted context omitted.

True, but you have to balance that against the small but nonzero number of people put off by an extra text field. Plus, I would find email repetition more annoying if I didn't always do Cmd-A/Cmd-C/Tab/Cmd-V, and in this case the repeated field won't catch any errors.

The fact that you know the shortcuts for select all, copy, and paste puts you in the top percentile of users. Most people don't even know that's possible, and certainly not with keyboard shortcuts. (The point being that for most users the faster approach that requires less thinking is to type it twice. Sometimes I do things the "slow" or "long" way when coding because it doesn't require a mental shift from the task a…

The point being that for most users the faster approach that requires less thinking is to type it twice.

Spoken like a touch-typist with a short email address. I feel confident in claiming that annabelle.t.johnson@woodandplaster.co.uk will be looking for that copypaste button. It's not like copypaste is a new technological innovation - it's practically the most used feature of personal computing, after backspace.

Re: Perfect email regex finally found

#105
post #39

Earlier quoted context omitted.

I also do simple email verification: 1) Send an email to the address. 2) If it succeeds, the address was valid.

So what happens when a mailserver uses greylisting to filter spam ?

Your outbound mailserver retries later and the message is delivered?

Re: Perfect email regex finally found

#106
post #86

"Now you have two problems." Seriously, I can't think of a single good reason why you would want to check whether an email address is "valid". What you should be concerned about is whether or not the address works (and usually, can/does the person who just signed up actually read and reply to email to that address). Hypothetically, if an invalid address works (due to bugs in mail systems) -- then it works, and the on…

Seriously, I can't think of a single good reason why you would want to check whether an email address is "valid"!

Because it's fun.

Re: Perfect email regex finally found

#108
post #8

Not perfect: doesn't support IDN without punycode. Doesn't support IDN TLDs at all. Users of http://موقع.وزارة-الاتصالات.مصر won't be pleased :)

At the risk of sounding flip, not supporting punycode sounds like a feature. Getting internationalization right is clearly important, but punycode as a means of doing so? It's one of the many things that make me weep for my industry.

In fact, I often wonder if punycode is a prank that got out of hand.

UTF-8, on the other hand, would have been excellent for this purpose.

Re: Perfect email regex finally found

#109
post #37
post #14

I've accepted that it's best to treat people like grown-ups and if there's '@' and '.' and it's retyped then it passes. Someone can easily submit a fake name or phone number or street address, and e-mail's no different. If they get it wrong, intentionally or not, then they don't get their receipt, confirmation, validation link, etc. and I believe in most cases the incentive is there for them to get it right. In the r…

Retyped!? Grown-ups can read what they write. Retyping only makes sense for password field, which is obfuscated and doesn't allow copy&paste.

Most forms asking for an email address use the same field name (or one of a limited number of field names), so the browser remembers what you typed last time, and it'll suggest it to you in a pop-up for autocompletion. All it takes is to type one letter, press down, and enter.

Not a lot of chance of mistyping, there;

Re: Perfect email regex finally found

#110
post #104
post #76

Earlier quoted context omitted.

The fact that you know the shortcuts for select all, copy, and paste puts you in the top percentile of users. Most people don't even know that's possible, and certainly not with keyboard shortcuts. (The point being that for most users the faster approach that requires less thinking is to type it twice. Sometimes I do things the "slow" or "long" way when coding because it doesn't require a mental shift from the task a…

The point being that for most users the faster approach that requires less thinking is to type it twice. Spoken like a touch-typist with a short email address. I feel confident in claiming that annabelle.t.johnson@woodandplaster.co.uk will be looking for that copypaste button. It's not like copypaste is a new technological innovation - it's practically the most used feature of personal computing, after backspace.

Good point. sami.samhuri@gmail.com takes me 3 seconds but might take someone else 10 seconds. Thanks for the perspective.
Post reply on HN