Hi,
I want to filter a string. Only the characters [A_Z] [0-9] and the +' and-' ( boolean operaters ) are allowd, the rest should be trashed. But since i'm a total noob on regexp (even after many, reading i still don't get it). I need some help 🙂
+' and
if(!preg_match("#[A-Za-z0-9-+]+#",$text_to_filter)) { //show error }
This checks that $text_to_filter is one or more characters, only A-Z a-z 0-9 or + or -
Simpler regexp:
/[^A-Z0-9+-]/
If that succeeds, then there was an invalid character (gavwin's code will show an error if there weren't any valid characters in the string).
You could also look at [man]strspn[/man] if you want to avoid regexps.