Page 1 of 1

Question: Allowing and disallowing characters from input

Posted: Thu Aug 04, 2005 11:19 am
by wutwolf
working on a script that will take input from several fields provided by a user and drop them into a variable, one for each. I want to be able to make sure there are no numbers in the name fields or alphas in the number fields, someone suggested the preg_match function, so this is how I implemented it but it didn't work, is it just my implementation or is there a better function or set of functions?

if (preg_match("/^[a-zA-Z]*$/", $fname))

assuming all the characters in the variable $fname are upper or lower case alpha's it should return a true/1 correct? but it's not working for some reason, is this the correct function? any thoughts on it?

Posted: Thu Aug 04, 2005 12:06 pm
by josh
Un-negate it, take out the ^ so when regex matches all a-zA-Z it will return true
also change the * to +, you dont want to match null do you?