note 60707 added to function.ctype-xdigit
| From: | tomathgmaildotcom at osu1 dot php dot net | Date: | Sat, 14 Jan 2006 20:36:41 +0000 |
| Subject: | note 60707 added to function.ctype-xdigit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101758@lists.php.net to get a copy of this message | ||
This function shows its usefulness on a web site where a user is asked to entered a hexidecimal
color code for a color. To prevent breaking W3C standard and having them enter in
"neon-green" or the wrong type of code like 355511235.
In conjunction with strlen() you could create a function like this:
function check_valid_colorhex($colorCode) {
// If user accidentally passed along the # sign, strip it off
$colorCode = ltrim($colorCode, '#');
if (
ctype_xdigit($colorCode) &&
(strlen($colorCode) == 6 || strlen($colorCode) == 3))
return true;
else return false;
}
----
Manual Page -- http://www.php.net/manual/en/function.ctype-xdigit.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60707
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60707&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60707&report=yes
Search -- http://master.php.net/manage/user-notes.php