Connecting Tech Pros Worldwide Forums | Help | Site Map

How to test a string for invalid chars ?

Pjotr Wedersteers
Guest
 
Posts: n/a
#1: Jul 17 '05
I think I am having a big blind-spot day. How does one test a form-sent
string for any disallowed characters again ? I want only a.z,A..Z,0..9,- and
_ in the input... Thanks.
Pjotr

--
The day Microsoft starts making stuff that does not suck will undoubtedly be
the day they start producing vacuum cleaners



Thomas Mlynarczyk
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to test a string for invalid chars ?


Also sprach Pjotr Wedersteers:
[color=blue]
> I think I am having a big blind-spot day. How does one test a
> form-sent string for any disallowed characters again ? I want only
> a.z,A..Z,0..9,- and _ in the input... Thanks.[/color]

if(!preg_match('/^[a-zA-Z0-9_-]*$/', $input)) {
echo 'Invalid input!';
}
else {
echo 'Well done!';
}



Closed Thread