PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Jan 08, 2004 6:09 am
I made this function to validate a alpha numeric but i'm a beginner in PHP so i would like to know if is there any other way.
Code: Select all
<?php
function CheckAlfaNum($strdata)
{
$charset = "abcdefghijklmnopqrstuvwxyz0123456789";
$length=strlen($strdata);
$length=$length-1;
$check=str_split($strdata);
for ($i=0;$i<=$length;$i++)
{
$itisthere = stripos($charset, $check[$i]);
if($itisthere === false)
{
return 1;
}
}
return 0;
}
?>
Pyrite
Forum Regular
Posts: 769 Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:
Post
by Pyrite » Thu Jan 08, 2004 6:16 am
Code: Select all
function is_alphanumeric($test) {
return (preg_match("/^[a-z0-9 ]+$/i", $test));
}
*Not My Code Though*
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Thu Jan 08, 2004 6:18 am
I don't have much of a clue of your question but str_split is a PHP5 function by the way
.
-Nay
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Jan 08, 2004 6:22 am
hmmm...
Code: Select all
function CheckAlfaNum($strdata){
return ereg("^[[]]+$",$strdata);
}
Pyrite
Forum Regular
Posts: 769 Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:
Post
by Pyrite » Thu Jan 08, 2004 6:22 am
Or explained better yet ..
http://us3.php.net/manual/en/function.ctype-alnum.php
Editors note:
CTYPE functions are always prefered, when possible, to Regular Expressions and, often, even to some equivalent str_*, is_* functions. This is because of the fact that CTYPE uses a native C library and thus processes signitificaly faster.
Maxim Maletsky
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Jan 08, 2004 6:27 am
Thanks a lot
.
I knew it, anyway i have reinvented the wheel, isn’t it?