Req #4268 [Opn->WFx]: Use of strspn() and strcspn() functions

From: Date: Sun, 08 Apr 2012 12:13:12 +0000
Subject: Req #4268 [Opn->WFx]: Use of strspn() and strcspn() functions
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-8532@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=4268&edit=1 ID: 4268 Updated by: borz_off@cs.msu.su Reported By: Philippe dot Jausions at 11abacus dot com Summary: Use of strspn() and strcspn() functions -Status: Open +Status: Wont fix Type: Feature/Change Request Package: HTML_QuickForm2 Operating System: Irrelevant PHP Version: Irrelevant Roadmap Versions: New Comment: -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. Previous Comments: ------------------------------------------------------------------------ [2006-06-08 10:36:13] avb Moving feature requests to HTML_QuickForm2. ------------------------------------------------------------------------ [2005-05-03 09:45:28] 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 ?> ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=4268&edit=1

« previous php.pear.bugs (#8532) next »