Jump to content

filter_var custom regex not working wondering why?


Eggzorcist

Recommended Posts

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!

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.