How to modify a preg_match function to accept spaces
Posted: Sun Sep 20, 2009 4:13 pm
How can I modify the below preg_match function to accept [letters][space][letters]. Want to still exclude numbers and other characters.
If it is easy, wouldn't mind excluding these entry options as well:
-[space][letters]
-[letters][space]
But, no big deal as I can trim those out when I post form.
I tried this but it didn't work
If it is easy, wouldn't mind excluding these entry options as well:
-[space][letters]
-[letters][space]
But, no big deal as I can trim those out when I post form.
Code: Select all
elseif(!preg_match("/^([a-zA-Z])+$/", $_POST['servingunits'])) {
$reqverrors[] = "Yes";
$errName = "\t<br><span class=pred>Units must be from letters and spaces.</span>\n";
}
I tried this but it didn't work
Code: Select all
elseif(!preg_match("/^([a-zA-Z[color=#FF0000] ]) ([ a-zA-Z])[/color]+$/", $_POST['servingunits'])) {
$reqverrors[] = "Yes";
$errName = "\t<br><span class=pred>Units must be from letters and spaces.</span>\n";
}