Behavior of the email address validator

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Behavior of the email address validator

Ralf Eggert
Hi,

I added a Zend\Form\Element\Email to my form and entered a@@com as an
input test. I get the following errors:

- The input does not match against pattern '/^[a-zA-Z0-9.!#$%&'*+\
  /=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/'
- 'com' is not a valid hostname for the email address
- The input does not match the expected structure for a DNS hostname
- The input appears to be a local network name but local network names
  are not allowed
- 'a@' can not be matched against dot-atom format
- 'a@' can not be matched against quoted-string format
- 'a@' is not a valid local part for the email address

All these messages might be technically correct. But to be honest, I
would not want to present all this stuff to an end user who tries to
enter his email address and makes a mistake. Especially the first one
with the pattern is a mess for any enduser.

Is it possible to reduce the error messages for the
Zend\Validator\EmailAddress somehow? Maybe we could add an expert and a
dummy mode which is just showing that the email address is wrong and the
user should check his input.

Any thoughts?

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

Garbage Dump
On the note of "the input appears to be a local network name but local network names are not allowed"
Several of my friends have email addresses issued by the top level domain server for Croatia.
Their email addresses are in the format:  <name>@hr

Just @hr ; nothing more.  Since that's the domain hosting their mail.
If you pull up the dns, you can verify it's MX record (it's one of the few that issued email addresses at the TLD level, and having MX records)

;; ANSWER SECTION:
hr.                     14399   IN      SOA     registrar.carnet.hr. hostmaster.carnet.hr. 1345671543 7200 3600 604800 3600
hr.                     14399   IN      MX      5 alpha.carnet.hr.

Is there any means to allow such email addresses through?

On Wed, Aug 22, 2012 at 2:53 PM, Ralf Eggert <[hidden email]> wrote:
Hi,

I added a Zend\Form\Element\Email to my form and entered a@@com as an
input test. I get the following errors:

- The input does not match against pattern '/^[a-zA-Z0-9.!#$%&'*+\
  /=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/'
- 'com' is not a valid hostname for the email address
- The input does not match the expected structure for a DNS hostname
- The input appears to be a local network name but local network names
  are not allowed
- 'a@' can not be matched against dot-atom format
- 'a@' can not be matched against quoted-string format
- 'a@' is not a valid local part for the email address

All these messages might be technically correct. But to be honest, I
would not want to present all this stuff to an end user who tries to
enter his email address and makes a mistake. Especially the first one
with the pattern is a mess for any enduser.

Is it possible to reduce the error messages for the
Zend\Validator\EmailAddress somehow? Maybe we could add an expert and a
dummy mode which is just showing that the email address is wrong and the
user should check his input.

Any thoughts?

Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

Jurian Sluiman
In reply to this post by Ralf Eggert
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

Ralf Eggert
Hi Jurian,

> $this->add(array(
>     'name'       => 'email',
>     'required'   => true,
>     'validators' => array(
>         array(
>             'name'    => 'EmailAddress',
>             'options' => array(
>                 'useDomainCheck' => false,
>                 'message' => 'The supplied email address is not a valid
> address'
>             )
>         )
>     ),
> ));

When I add this I get the following error:

Fatal error: Call to a member function setMessage() on a non-object in
/home/devhost/zf2domain/vendor/zendframework/zendframework/library/Zend/Validator/EmailAddress.php
on line 125

That error makes sense, since $this->options['hostnameValidator'] can be
null. A check should be added there.

> This also brings me to another "bug" in the email validation chain: if I
> enter a@@com in this email field, I get three times the message "The
> supplied email address is not a valid address". I guess when you set the
> same message to all types of errors, you only want to see one message when
> multiple errors occur.
>
> For the real experts you might display all the seven (!) messages Ralph
> shows in above post, but when all messages are set equally, you probably
> want to display them only once.

Yes, that is a problem. Should I create an issue for this?

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

weierophinney
Administrator
-- Ralf Eggert <[hidden email]> wrote
(on Thursday, 23 August 2012, 10:08 PM +0200):

> Hi Jurian,
>
> > $this->add(array(
> >     'name'       => 'email',
> >     'required'   => true,
> >     'validators' => array(
> >         array(
> >             'name'    => 'EmailAddress',
> >             'options' => array(
> >                 'useDomainCheck' => false,
> >                 'message' => 'The supplied email address is not a valid
> > address'
> >             )
> >         )
> >     ),
> > ));
>
> When I add this I get the following error:
>
> Fatal error: Call to a member function setMessage() on a non-object in
> /home/devhost/zf2domain/vendor/zendframework/zendframework/library/Zend/Validator/EmailAddress.php
> on line 125
>
> That error makes sense, since $this->options['hostnameValidator'] can be
> null. A check should be added there.

Are you working on current master? There was a fix for that earlier
this week, IIRC.


> > This also brings me to another "bug" in the email validation chain: if I
> > enter a@@com in this email field, I get three times the message "The
> > supplied email address is not a valid address". I guess when you set the
> > same message to all types of errors, you only want to see one message when
> > multiple errors occur.
> >
> > For the real experts you might display all the seven (!) messages Ralph
> > shows in above post, but when all messages are set equally, you probably
> > want to display them only once.
>
> Yes, that is a problem. Should I create an issue for this?
>
> Regards,
>
> Ralf
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

Ralf Eggert
Hi Matthew,

>> Fatal error: Call to a member function setMessage() on a non-object in
>> /home/devhost/zf2domain/vendor/zendframework/zendframework/library/Zend/Validator/EmailAddress.php
>> on line 125
>>
>> That error makes sense, since $this->options['hostnameValidator'] can be
>> null. A check should be added there.
>
> Are you working on current master? There was a fix for that earlier
> this week, IIRC.

Well, I am using RC4 currently. But I look here before sending an issue
or mail. So I am not sure, if this is the current master:

https://github.com/zendframework/zf2/blob/master/library/Zend/Validator/EmailAddress.php

But the problem seems still to be in there on line 125. Since the
$options['hostnameValidator'] can be set to null in the constructor the
fatal error can be thrown.

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of the email address validator

avirdz
This post has NOT been accepted by the mailing list yet.
In reply to this post by Ralf Eggert
Hello Ralf

I have the same problem with current version of ZF 2.3.2.

The input does not match against pattern '/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/'

I tried to set the message for key: regexNotMatch, but I get the following error:
No message template exists for regexNotMatch

Any solution for this issue?
Thanks :)