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! Link to comment https://forums.phpfreaks.com/topic/222655-filter_var-custom-regex-not-working-wondering-why/ 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? Link to comment https://forums.phpfreaks.com/topic/222655-filter_var-custom-regex-not-working-wondering-why/#findComment-1151478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.