Valid Chars....no fun!

From: Date: Mon, 13 Sep 2004 01:07:51 +0000
Subject: Valid Chars....no fun!
Groups: php.general 
Request: Send a blank email to php-general+get-196461@lists.php.net to get a copy of this message
Hi! I got this code from here, i think it was "Ni Shurong" who gave it to me. The code works pretty good. Except i found that sending "asdas." into the function will return true...it should return false. What i am trying to do is check for valid chars. Only alpha and numeric. Can someone help me correct the code: function isValid($strData, $bIncludeAlpha=false, $bIncludeNumber=false) {
     switch(true) {
         case $bIncludeAlpha && !$bIncludeNumber:
             $ptr = "/^[a-zA-Z]+/";
             break;
         case !$bIncludeAlpha && $bIncludeNumber:
             $ptr = "/^[0-9]+/";
             break;
         case $bIncludeAlpha && $bIncludeNumber:
             $ptr = "/^[a-zA-Z0-9]+/";
             break;
         default:
             return false;
     }
     return preg_match($ptr, $strData);
} Thanx In Advance Jay

« previous php.general (#196461) next »