|
I'm trying to do some form validation in php using preg_match. This is what I would like to allow:
Any letters from a-z, regardless of case
can include the characters . - ' ,
can include spaces
all of the above should be allowed to be in any order throughout the string.
I do not want it to include numbers, semi-colons, colons, hash (pound sign), back or forward slashes, brackets (either curly or square), dollar signs, greater than or less than signs, or other characters such as that.
I have written:
Code:if (!preg_match("%[a-zA-Z\.\,\-\'\ ]%",$field_name))
{
invalid output would go here
exit;
}
It must be wrong because I am allowed to enter things like ...
O'Sm#ith
Smith 1
Smith1
I haven't the foggiest I idea how to correct my problem. I've had a look at some regexp sites to try to debug my syntax, but that this point I'm lost. Can anyone give me some hints?
Cheers
Heiko
Last edited by Tinkli; 01-20-2011 at 11:00 PM..
|