note 92393 added to function.ctype-alnum
| From: | thinice at gmail dot com | Date: | Wed, 22 Jul 2009 21:46:28 +0000 |
| Subject: | note 92393 added to function.ctype-alnum | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158595@lists.php.net to get a copy of this message | ||
ctype_alnum() is a godsend for quick and easy username/data filtering when used in conjunction with
str_replace().
Let's say your usernames have dash(-) and underscore(_) allowable and alphanumeric digits as
well.
Instead of a regex you can trade a bit of performance for simplicity:
<?
$sUser = 'my_username01';
$aValid = array('-', '_');
if(!ctype_alnum(str_replace($aValid), '', $sUser)) {
echo 'Your username is not properly formatted.';
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 134.29.231.10
----
Manual Page -- http://www.php.net/manual/en/function.ctype-alnum.php
Edit -- https://master.php.net/note/edit/92393
Del: integrated -- https://master.php.net/note/delete/92393/integrated
Del: useless -- https://master.php.net/note/delete/92393/useless
Del: bad code -- https://master.php.net/note/delete/92393/bad+code
Del: spam -- https://master.php.net/note/delete/92393/spam
Del: non-english -- https://master.php.net/note/delete/92393/non-english
Del: in docs -- https://master.php.net/note/delete/92393/in+docs
Del: other reasons-- https://master.php.net/note/delete/92393
Reject -- https://master.php.net/note/reject/92393
Search -- https://master.php.net/manage/user-notes.php