Brett
Brett

Reputation: 20049

Regex saying there are spaces in text when there is none

I'm trying to check a string for spaces, tabs et al & am using this:

if (preg_match('/\s*/', $username)) {
    echo 'no spaces allowed in username.';
}

However it always thinks there are spaces in the username even if there isn't.

What am I doing wrong?

Upvotes: 0

Views: 44

Answers (1)

Marko D
Marko D

Reputation: 7576

* means zero or more times.

So

if (preg_match('/\s+/', $username)) {

Upvotes: 5

Related Questions