My scriptygoddess crown to the first person that can give me the PHP code to validate a form field so that no special characters are allowed…
(well, okay it's not really a crown; more like a plastic tiara… how about lots of plugs here, and the good feeling that you've helped out a friend in need?) 😀
UPDATE: Nevermind! I got it! (YAY! I get to keep my tiara!!) ;-P
(Update again: Actually, Amy saw my function and raised it… her's is better/quicker/easier, etc.)
Amy is the grand champion Tiara holder!! 😉
Here's a php function that will return true if the character is alphanumeric, and false if it's anything else:
Here's mine (Amy's is better though…)
function noSpecialChars($string) {
$validate = true;
for ($i=0; $i < strlen($string); $i++) {
if (!ereg("[a-zA-Z0-9]", $string{$i})) {
$validate = false;
}
}
return $validate;
}
(so simple… yet, I will never admit to how many hours it took me to figure that damn thing out!!!)
Of course, what this function is doing is checking every single character… probably a bit of "server overhead" so if you have a simpler option… I'm all ears… well, eyes. 😉
Here's Amy's:
function is_alphanumeric($test) {
return (preg_match("/^[a-z0-9 ]+$/i", $test));
}