I'm trying to make sure a search text field has only numbers, letters, or
spaces.
I started with this:
$pattern = "^([ 0-9a-z])";
if (eregi($pattern, $search_txt)) {
And that works so long as the 1st character isn't a number or letter,
otherwise it allows the whole string.
I did some newsgroup looking, and everything I've found has been for very
complex checks like e-mail addresses.
The simplest example I could find is:
$pattern = "[a-z0-9_\-]+";
if (eregi($pattern, $search_txt)) {
Which evidently also checks against only 1 letter searches, which is also
useful. But it still allows searches that contain both valid and invalid
characters. It only refuses patters that are only invalid.
This is something that's so rediculously simple...but is still beyond me. =/
Any suggestions?
Thanks,
Liam