Regular Expressions! ..php ereg?

Associate
Joined
15 Jan 2003
Posts
1,117
Location
Bristol/Manchester Uni
Hey,

Haven't done regular expressions in awhile and just trying to piece together some validation rules for a few input forms.

I want to catch any input that is NOT alphanumeric, so ALL symbols/illegal characters etc. BUT the problem is I want to allow spaces.

So my question is, what symbol is it to exclude (or include depending on how you look at it) from being matched. As currently I have the following which works as I want except for the spaces being picked up as invalid!

Code:
(ereg("[^A-Za-z0-9]|[0-9]", $this->jobtitle))

^ obviously this is wrapped in an if statement.

Have tried googling, but I keep getting loads of tutorials on how to do regular expressions with examples for matching email addresses and the like; not how each symbol is handled etc.

Any help greatly appreciated,
Many thanks.

Lewis.
 
Give this a bash:

if (preg_match('/^[a-z0-9 ]$/i', $this->jobtitle)) {
// only contains alpha-numeric chars or spaces
}

That hasn't worked unfortunately, as it's now allowing symbols. Spaces are now valid but all symbols should be invalid.
Appreciate reply though!
 
Back
Top Bottom