MySQL_Narb Posted August 26, 2012 Share Posted August 26, 2012 if(preg_match('/[^a-zA-Z0-9_ ]/', $username)) $err = 1; Any idea why that returns: Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/a4205434/public_html/structure/user.register.php on line 64 Quote Link to comment https://forums.phpfreaks.com/topic/267627-preg_match/ Share on other sites More sharing options...
xyph Posted August 26, 2012 Share Posted August 26, 2012 No error generated with that code here. You've messed up elsewhere Quote Link to comment https://forums.phpfreaks.com/topic/267627-preg_match/#findComment-1372683 Share on other sites More sharing options...
MMDE Posted August 26, 2012 Share Posted August 26, 2012 I got a feeling you're trying to do this instead: preg_match('/^[a-zA-Z0-9_ ]/', $username) Though, this can not be used to sanitize input, as it matches always when the first letter in one of the lines in $username is one of these: "a-zA-Z0-9_ ", no matter what is afterwards, or if it is several lines. I think you want this: if(preg_match('/\A[a-zA-Z0-9_ ]+\Z/', $username)){ //$username is "safe" to use in a mysql query } Please do correct me if this is not a good regex to sanitize user input. Quote Link to comment https://forums.phpfreaks.com/topic/267627-preg_match/#findComment-1372692 Share on other sites More sharing options...
Christian F. Posted August 26, 2012 Share Posted August 26, 2012 MMDE: If you take a second look at the code he posted, it'll set $err = 1 if the pattern matches. In other words, exactly what you'd want for validation. Quote Link to comment https://forums.phpfreaks.com/topic/267627-preg_match/#findComment-1372694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.