ZF-11479: Use php filter_var function for validators

Issue Type: Improvement Created: 2011-06-14T11:22:34.000+0000 Last Updated: 2011-06-15T22:17:01.000+0000 Status: Resolved Fix version(s): Reporter: Karim Cassam Chenaï (ka) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Validate

  • validating

Related issues: Attachments:


Zend_Validate does not use php built-in filter_var function. Here is a list of Validate filters that could be implemented :…

I did an example for email :…


Posted by Matthew Weier O'Phinney (matthew) on 2011-06-14T13:57:19.000+0000

The email validator as currently written actually covers more cases than found in PHP's filter_var() functionality, and this is true of a large number of the various validators that have similar counter-parts in filter_var(). (Most ZF validators can be locale-aware, allowing for more flexible validation than filter_var() offers).

BTW, you might be interested in Zend_Validate_Callback, which allows you to specify your own callback for validations. When used in PHP 5.3, this allows you to curry arguments in and pass them to filter_var() easily:

<pre class="highlight">
$validator = new Zend_Validate_Callback(function($value) {
    return filter_var($value, FILTER_VALIDATE_EMAIL);

One nice part of this validator is that you can also pass in custom error messages. :)

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2011-06-14T16:36:41.000+0000

In addition to what Matthew already said. PHP's filter_var functionality is often buggy. Try running the Zend_Validate testsuite against the filter_var() features and you'll find out that zend_Validate sticks better to the RFC's than filter_var by far.

Posted by Karim Cassam Chenaï (ka) on 2011-06-15T22:17:01.000+0000

OK, Thank you for the clarification :)

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.