note 25457 added to ref.strings
| From: | madime at yahoo dot com | Date: | Tue, 24 Sep 2002 17:07:31 +0000 |
| Subject: | note 25457 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37194@lists.php.net to get a copy of this message | ||
Here's a better IsAlphaNumeric() function than those listed above. It is an enhancement of
jewfish@jewfish.net's suggestion.
My example below allows you to pass $Type for allowing you to exclusively test alpha or numeric or
both. It also allows you to pass $IgnoreChar to list what characters are permissible in the test,
such as spaces, commas, quotes, etc.
function IsAlphaNumeric($TestValue,$Type=3,$IgnoreChar="") {
#Returns TRUE if $TestValue passes the AlphaNumeric test
# of $Type, or FALSE if it doesn't pass it.
#$Type allows for specifying what to test for:
# 1 = Alpha Only
# 2 = Numeric Only
# 3 = AlphaNumeric
#IgnoreChar is a string of values to ignore in the search
# such as spaces, commas, quotes, etc.
switch($Type){
case 1:
return !(preg_match("/[^a-z,A-Z$IgnoreChar]/", $TestValue));
break;
case 2:
return !(preg_match("/[^0-9$IgnoreChar]/", $TestValue));
break;
default:
return !(preg_match("/[^a-z,A-Z,0-9$IgnoreChar]/", $TestValue));
}
}
--
http://www.php.net/manual/en/ref.strings.php
http://master.php.net/manage/user-notes.php?action=edit+25457
http://master.php.net/manage/user-notes.php?action=delete+25457
http://master.php.net/manage/user-notes.php?action=reject+25457