Eggzorcist Posted December 26, 2010 Share Posted December 26, 2010 I'm having a lot of trouble validating things using custom regex. I'm trying to validate usernames without spaces using numbers and/or letters with optional underscores. This is my code but it isn't validating anything, nothing is ever validated. Whatever I write it says the username isn't valid. if(isset($_POST['submit'])){ if(filter_var($_POST['value1'], FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[\w.-]{{3},{28}}$/")))){ echo "Value is a valid username."; } else { echo "Value is NOT a valid username."; } } ?> Any help regarding this issue will be greatly appreciated. Thanks! Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 26, 2010 Share Posted December 26, 2010 A couple of things, are you positive that your actual regular expression pattern is working? I suggest using http://gskinner.com/RegExr/ to mess with it. If it is, I have to ask, why are you using the filter_var way of validating a string against a regular expression, why not just do a if (preg_match(... then if it true or not? Quote Link to comment 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.