I’ve run into a curious problem with preg_match() and backslashes. I’m trying to check a username for illegal characters. It works with almost everything but apparently usernames like ‘BobDobbs\’ are getting through.
I’ve managed to work around the problem easily enough with strpos() but I’m still not sure what’s wrong with my syntax. Running PHP 5.3.10.
$displayname = 'BobDobbs\\\\';
if(preg_match("/[^A-z0-9_.-]/", $displayname)) {
$errors[] = 'Name contains illegal characters';
}
The range
A-zcontains the\character. I think you’re looking fora-zA-Zinstead.(
Ais 65,zis 122, and\is 92.)