zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

Unconventional behavior in EmailAddress validator #41

Open Saeven opened 9 years ago

Saeven commented 9 years ago

Configuring a 'message' option on validators should return that single message on failure. (ref http://framework.zend.com/manual/current/en/modules/zend.validator.messages.html)

The second parameter defines the failure which will be overridden. When you omit this parameter, then the given message will be set for all possible failures of this validator.

I have a simple field in a sign up form whose counterpart InputFilter contains this configuration:

'validators' => [
                [
                    'name' => EmailAddress::class,
                    'options' => [
                        'useMxCheck'        => true,
                        'useDeepMxCheck'    => true,
                        'useDomainCheck'    => true,
                        'message'           => _( "Hey bud, check your email." ),
                    ],
                ],

In this case, unfortunately, we get a regex failure that's pretty cryptic on top of what we've set.

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

The message configured should preempt the regex failure.

Maks3w commented 9 years ago

Are you using InputFilter? Then message could be defined at the same level of the input and should works too (Except the same message its used for every validator)

Maks3w commented 9 years ago

Also the behavior its supposed to be tested https://github.com/zendframework/zend-validator/blob/master/test/EmailAddressTest.php#L594

Please check again and provide a unit test showing the issue

Saeven commented 9 years ago

Here's a quick repo that exhibits the behavior: https://github.com/Saeven/validator_test

Can see it from the command line. Email element types are being duplicitous it seems! ;)

michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at https://github.com/laminas/laminas-validator/issues/45.