note 92393 modified in function.ctype-alnum by colder
| From: | colder@php.net | Date: | Mon, 18 Jul 2011 12:10:00 +0000 |
| Subject: | note 92393 modified in function.ctype-alnum by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181634@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:
<?php
$sUser = 'my_username01';
$aValid = array('-', '_');
if(!ctype_alnum(str_replace($aValid, '', $sUser))) {
echo 'Your username is not properly formatted.';
}
?>
--was--
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:
<?php
$sUser = 'my_username01';
$aValid = array('-', '_');
if(!ctype_alnum(str_replace($aValid), '', $sUser)) {
echo 'Your username is not properly formatted.';
}
?>
http://php.net/manual/en/function.ctype-alnum.php