Welcome aboard LawGen, first,
[\w-]
Within a
class, a dash usually means a range, as in a-z is all letters. \w may not suffice, as it is a word character, not always specifically letters.
All I want, is to allow individuals the opportunity to have spaces in their username.
The way I would go about this is a
not - as in, anything not a letter, number, dash, or space. inside a class, ^ as the first character means "anything not these." In the regular course of a regex, it means "start of string."
if (preg_match('/[^a-z0-9\s\-]+/i', $data['username'])) { echo "ERROR"; }
else { echo "OK"; }
I left the dash in there in case you want it, as you can see it's escaped. Translated, the whole thing is "if the string contains anything not a case-insensitive (i modifier) letter, number, space, or dash, error, otherwise, OK."
You can skip the "else" if "echo error" actually exits.