Why doesn't this regular expression work with spaces?

JudyTeen

New Member
How do I make the following regular expression accept only the symbols I want it to accept as well as spaces?\[code\]if(!preg_match('/^[A-Z0-9\/\'&,.-]*$/', $line)){ die();}else{ //execute the rest of the validation script}\[/code\]I want the user to only be able to enter A-Z, 0-9, forward slashes, apostrophes, ampersands, commas, periods, and hyphens into a given text field $line.It currently will accept something along the lines of HAM-BURGER which is perfect, it should accept that. I run into an issue when the user wants to type HAM BURGER (<- note the space).If I remove the ^ from the beginning and/or the $ from the end it will succeed if the user types in anything. My attempted remedy to this was to make the * into a + but then it will accept anything as long as the user puts in at least one of the acceptable characters.
 
Back
Top