I need to create a regular expression that replaces more than one space character with just one.
It is for a username registration page and I want to ensure that a user can not type more than one space character in a row.
My grasp on regular expressions is pretty small so any help would be very welcome.
Ben.
You could do this: $new_username = ereg_replace("[^ ]*", " ", $username);
It's probably not the fastest way but it should work.
-jmk
The regular expression of jmk returns a string with only spaces.
The following returns a string with all occurences of one or more spaces (or tabs or newlines) replaced with one space:
$new_username = preg_replace('/\s+/', ' ', $username);