Re: Valid Chars Function
| From: | Jason G. | Date: | Mon, 19 Nov 2001 11:16:36 +0000 |
| Subject: | Re: Valid Chars Function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-75103@lists.php.net to get a copy of this message | ||
Well, you can make good use of regular expressions, or write your own function.
(It turns out i needed the functions, so I just wrote them, and included them here)
******************************************************
//This regex checks for > 1 letters in a string - anything else will fail
if(ereg('^[a-z|A-Z]+$', $sName))
echo 'Valid';else
echo 'Invalid';****************************************************** //Returns TRUE if all characters in sString are found in sValidChars function ValidChars($sValidChars, $sString) {
$len = strlen($sString);
for($i=0; $i<$len; $i++)
if(strpos($sValidChars,$sString[$i])===FALSE)
return FALSE;
return TRUE;
}
******************************************************
//Returns TRUE if none characters in sString are found in sValidChars
function InvalidChars($sValidChars, $sString)
{
$len = strlen($sString);
for($i=0; $i<$len; $i++)
if(strpos($sValidChars,$sString[$i]))
return FALSE;
return TRUE;
}
******************************************************
-Jason Garber
IonZoft.com
At 01:28 AM 11/19/2001 -0600, phantom wrote:
Anyone know a good PHP function or script to scan a string for Valid Characters to make sure something that is not allow is not included in a form? $Name = "#@@##@!#!@" would not be a valid alphabetical name, how do I scan for that in PHP? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net