4 ms·
In general terms I absolutely agree with you. However, the subtleties might have more to do with ensuring that the intent of the transaction is adhered to rath
by robomartin 14y ago
In general terms I absolutely agree with you. However, the subtleties might have more to do with ensuring that the intent of the transaction is adhered to rather than not.
The first assumption is that your intent is to capture accurate user information and the user's intent is to give it to you.
With that established, it is a good idea to apply sensible measures at your end in order to ensure that the data is accurate.
Then there's the reduction of junk signups and the like. This is a case where your user doesn't necessarily have to know that you are validating. You can simply tag the signup as potentially invalid in the database and require human inspection or discard it if there's enough information to do so. In other words, the validation happens in the server and with no feedback to the client.
The RFC822 regex expression will pass something like this as valid:
joe @example.com
joe@ example .com
joe@example.ccom
joe@example.com-
joe@example.com----------------
joe@example.com/////
You can check it yourself here:
http://mythic-beasts.com/~pdw/cgi-bin/emailvalidate http://mythic-beasts.com/~pdw/cgi-bin/emailvalidate
I haven't done exhaustive testing on that particular expression. I don't really know where it fails. And that's part of the problem.
If the "contract" is that both parties want this information to be correct the user couldn't possibly be annoyed if you point out a legitimate error in the email address. You can prevent a situation where someone fills out a form, clicks "send" and goes away thinking that the signed-up when they actually didn't because they made a mistake entering their email address. What are you going to do? Send them an email?
Obviously, if they enter
jjoe@somedomain.com
instead of
joe@somedomain.com
The only hope you have to catch it is to make them enter it twice and hope they don't make the same mistake twice. This is ugly and bad for such things as landing page signup forms. People don't generally respond well to having to type their address twice.
So, yes, even with validation you are going to loose a few.
What you are going to catch are cases where the email is entered with detectable mistakes:
jot dot@somedomain.com
jotdot@@somedomain.com
jotdot@somedomain.com.
jotdot@ somedomain.com
jotdot@somedomain..com
jotdot@ somedomain.comm
etc.
instead of
jotdot@somedomain.com
With a good email validation approach --which includes DNS checks-- you can catch most of these and alert the user. I don't think this is a bad idea at all.
While it is true that that super-large regex expression seems to validate most addresses correctly, there's a voodoo out there in the realm of regex for email validation. Buyer beware.
- yakiv 14y agoIs "jotdot@somedomain.com." actually invalid? My understanding is that something like "example.com." represents the same domain name as "example.com" does. I don't know if things work differently for email addresses, though.
- robomartin 14y agoI think you might be confusing absolute or rooted FQDNs (Fully Qualified Domain Name) and relative FQDNs (in the context of DNS) with valid or invalid email addresses. An absolute FQDN ends with a period: apple.com. A relative FQDN does not: apple.com When a DNS resolver sees an absolute FQDN it has a pretty direct path to getting the corresponding IP address. If, instead, the resolver is looking at a relative FQDN it does not, and it tries to fix it, and it could go around in circles for a while depending on where the resolver is running. What the resolver does is add different forms of DNS suffixes it has available until it either figures it out, fails or times out. For example, if the resolver is running on www.example.com, it might try the following: apple.com.www.example.com. apple.com.example.com. apple.com.com. If it finds any CNAME records it will follow them and go around in circles some more. I ran across this recently while looking at the whole issue of email validation through DNS. So, this is fresh pain you are hearing about! Here's my post on SO: http://stackoverflow.com/questions/14065946/what-would-cause-checkdnsrr-or-dns-get-record-to-take-too-long http://stackoverflow.com/questions/14065946/what-would-cause... I also have a DNS function test page on one of my sites here: http://www.tommyteaches.com/test/test2.php http://www.tommyteaches.com/test/test2.php If you try a domain like "notarealdomain1.com" you'll see that it takes a while (20 to 30 seconds per test) for the DNS functions to resolve it. If, instead, you enter "notarealdomain2.com." (period at the end) the DNS resolver will come back almost immediately. This is due to the DNS suffix append mechanism described above. Note that if you enter the same name twice, the second test will return faster due to caching. Here's an interesting read: http://tools.ietf.org/html/rfc1535 http://tools.ietf.org/html/rfc1535