Can someone help me with this regular expression?
It seems to be blocking some names without spaces and special characters. Names constisting of just letters and numbers.Code:if(!preg_match("^[A-Za-z0-9]+$^", "$username"))
| SitePoint Sponsor |





Can someone help me with this regular expression?
It seems to be blocking some names without spaces and special characters. Names constisting of just letters and numbers.Code:if(!preg_match("^[A-Za-z0-9]+$^", "$username"))


I don't know that using a caret ^ is the best choice for a delimiter, but are you trim()ing the $username ?





I'm pretty sure I am trimming. What delimiter should I use?


Forward slash and pound are pretty common delimiters since they don't appear in most expressions. The carat is confusing since that's also the start-of-line indicator and a negation operator within the regex. Since you don't have a carat other than the delimiter at the front of your pattern, usernames that don't meet your criteria will actually pass that test.
Do you have an example of the ones making it through that you don't want to?
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.

If you only want letters and numbers then do this it is quicker:PHP Code:if(!ctype_alnum($username))
Kayzio - We don't hesitate, we accelerate.
Bookmarks