The email form should be using validation.

Comments

ullgren’s picture

form components with type 'email' will now be validated.
using

eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+[\.[a-zA-Z.]{2,5}]*$', $value)
ullgren’s picture

Assigned: Unassigned » ullgren
Status: Active » Fixed
Marc Bijl’s picture

Hi Pontus,

You're doing a great job man! Lots of activity last few hours / days (:

I have a question regarding your post at this issue: is this some code we need to integrate somewhere, or did you update the module itself? Just downloaded webform.module 4.6 but couldn't find anything that looked the same as the code suggested here.

ullgren’s picture

No I commited the change to CVS. It takes a few hours before the drupal site repacks the tar.gz file.
But you can get the fixed version directly from CVS

Marc Bijl’s picture

Thanks mate, great job!

Marc Bijl’s picture

Status: Fixed » Needs work

Hi Pontus,

Not sure, but I think a small thing need to be checked. At my site one kind of address is accepted while I think it's invalid, e.g. a@a.a. Here's an overview:

a@a. = not accepted
a@a.a = accepted -> wrong?
a@a.aa = accepted
a@a.aaa = accepted
a@a.aaaa = accepted
a@a.aaaaa = not accepted

I have to say, I'm not a programmer. But I tried to look at the internet and found some information about eregi. Can it be something goes wrong with the part {2,5} ?

Sorry if I'm wrong...

ullgren’s picture

Acctually all addresses that has a @ in it is a valid email.
since drupal could be deployed on a intranet where (as in my case) we don't use any real top level domains (for example my internal email address could be ullgren@intranet).
It's just a matter of setting up a MX record for the domain intranet in your network private DNS.

Any way I also figured out that the eregi I used does not handle subdomains such as a@aaaa.bb

A better eregi is

eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5})$', $value)

Problem here is that it does not handle the @intranet type of domain I'm using. But I guess this is not that important. So I've commited it.

ullgren’s picture

I meant to write
"subdomains such as a@aaaa.bbbbb.ccc"

heine’s picture

E-mail validation is wrought with problems. It is so difficult that many scripts don't get it right. Remember the time .info was introduced and many feedback forms refused to allow these valid addresses?

Why limit the TLD to 5 characters? As far as I know there's no such limit. .museums, .africa, .sansansan were all requested as gTLD and who knows, may be approved. Additionally some large non-internet connected organizations may use e-mail addresses such as first.last@group.network.

Also: does the current regexp work with the valid space and quotes containing e-mail address "First Last"@organization.org ?

ullgren’s picture

As I said (or at least tried to) in the prevoius comment this is not a 100% standard compliant way to check the email address since as you say there are no upper limmit length of the TLD or in that there should be a TLD at all in the email address (I my self live in with the use of the the user@organisation type of addresses internaly).

But without any of the current limitation checks it would only be a test that there are only one @ character in the string. And even this is not 100%. Say that the user uses a drupal installation on the localhost then just username would be a sufficent email address for most mail systems.

No it doesn't work for quoted-string. In fact I was just on my way to say "That can't be valid ..." but a quick look at rfc2821 proved me wrong =(

So what is the verdict ?
1. Remove the check since there are no 100% standard way to solve this.
2. Live with the fact that the check is not 100% accurate when it come to folowing the standard and add it as a option ("non-standard email address checking") in the settings ?
3. Implement a method that contacts the server handeling the emails for the domain and do a VRFY on the mailbox ?

Also I thing .museum (which is six characters where approved).

Marc Bijl’s picture

In my opinion:

#1 = no option
#2 = good option
#3 = best option (?)

Explanation:
As I'm more a designer than a programmer, I have to say this is all new for me. Therefore #3 just sounds like the best option to me, althoug I cannot estimate at all how it's quality and completeness relates to #2 (just like how much effort it takes to realise - wish I had the skills to help and create a patch).

So, #2 would be great for me!

BTW
In case #3 will be chosen: is it possible to implement it as an option too?

ullgren’s picture

Status: Needs work » Closed (fixed)

While I agree with you that option #3 would be the best I decided to take option #4 =)

I found the a function "valid_email()" in the drupal core. This is a regexpresion check of the email address and it has some flaws (such as not allowing the quoted string mailbox name). But I think that this is the best solution non the less since it gives consistensy. If you can register to the site using a email addrress you can also use it when submitting forms.

Marc Bijl’s picture

Okay, no worries. But how can I use it: is it part of latest CVS webform.module now?

ullgren’s picture