snippet library logo
The Best Html Forum Around
in category
PHP / Authentication / Alphanumeric string or not?
Snippet details
ID: 118
Viewed: 1489
Added: 2002-04-14
Version:
Sorry no demo

User Rated at:
Rate This:
Snippets in this catagory         
Show Printable Version
This is a function, that will return false if the string passed to it is not alphanumeric, and true if it is.

General Details
Snippet uploaded by: Ric Mitchell
Email : ricmitch_uk@yahoo.com
Snippet By: Ric Mitchell

<!---Head--->
none

<!---Body--->


<?

function alphanumeric($string) {
    
$alphachars[0] = "9";
    
$alphachars[1] = "a";
    
$alphachars[2] = "b";
    
$alphachars[3] = "c";
    
$alphachars[4] = "d";
    
$alphachars[5] = "e";
    
$alphachars[6] = "f";
    
$alphachars[7] = "g";
    
$alphachars[8] = "h";
    
$alphachars[9] = "i";
    
$alphachars[10] = "j";
    
$alphachars[11] = "k";
    
$alphachars[12] = "l";
    
$alphachars[13] = "m";
    
$alphachars[14] = "n";
    
$alphachars[15] = "o";
    
$alphachars[16] = "p";
    
$alphachars[17] = "q";
    
$alphachars[18] = "r";
    
$alphachars[19] = "s";
    
$alphachars[20] = "t";
    
$alphachars[21] = "u";
    
$alphachars[22] = "v";
    
$alphachars[23] = "w";
    
$alphachars[24] = "x";
    
$alphachars[25] = "y";
    
$alphachars[26] = "z";
    
$alphachars[27] = "0";
    
$alphachars[28] = "1";
    
$alphachars[29] = "2";
    
$alphachars[30] = "3";
    
$alphachars[31] = "4";
    
$alphachars[32] = "5";
    
$alphachars[33] = "6";
    
$alphachars[34] = "7";
    
$alphachars[35] = "8";
    for (
$i=0;$i<strlen($string);$i++) {
        for (
$j=0;$j<36;$j++) {
            if(
strtolower(substr($string$i1)) == $alphachars[$j]) {
                
$charok == 1;
            }
        }
        if (!
$charok) {
            return 
false;
        }
        
$charok NULL;
    }
    return 
true;
}

?>




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.