Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.4.0

Request #4268 Use of strspn() and strcspn() functions
Submitted: 2005-05-03 13:45 UTC
From: jausions Assigned:
Status: Wont fix Package: HTML_QuickForm2
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-05-03 13:45 UTC] jausions
Description: ------------ For the lettersonly, alphanumeric and nopunctuation rules, I suggest to use the PHP strspn() and strcspn() function instead of heavy weight regexp. By the way, is it intentional that not all punctuation characters are in the list of forbidden characters? Missing from the list are: ` & - ; Reproduce code: --------------- In HTML_QuickForm_Rule_Regexp <?php function validate($value, $regex = null) { switch ($this->name) { case 'lettersonly': case 'alphanumeric': case 'nopunctuation': switch ($this->name) { case 'lettersonly': $str = 'abcdefghijklmnopqrstuvwxyz'; $function = 'strspn'; break; case 'alphanumeric': $str = 'abcdefghijklmnopqrstuvwxyz0123456789'; $function = 'strspn'; break; case 'nopunctuation': $str = '().`;\\|/*^?#!@$&%+=-,"\'><~[]{}'; $function = 'strcspn'; break; } return (strlen($value) != $function(strtolower($value, $str))) ? false : true; break; } if (isset($this->_data[$this->name])) { if (!preg_match($this->_data[$this->name], $value)) { return false; } } else { if (!preg_match($regex, $value)) { return false; } } return true; } // end func validate ?>

Comments

 [2006-06-08 14:36 UTC] avb (Alexey Borzov)
Moving feature requests to HTML_QuickForm2.
 [2012-04-08 17:13 UTC] avb (Alexey Borzov)
-Status: Open +Status: Wont fix
We no longer have a list of built-in regexps in QF2. Also usage of these functions is not easily translated into Javascript.