Question: Allowing and disallowing characters from input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wutwolf
Forum Newbie
Posts: 1
Joined: Thu Aug 04, 2005 11:13 am

Question: Allowing and disallowing characters from input

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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?
Post Reply