Jump to content

[SOLVED] help with reg expression


RyanSF07

Recommended Posts

Hi Guys,

 

I don't understand why the following permits % symbols. Isn't this saying "only allow upper and lower case letters, numbers, underscores, hyphens and/or white spaces"?

 

That's what I'd like it to be --- what am I doing wrong?

 

Thank you for your help ~

 

if (eregi("^[a-zA-Z0-9_\-]|[:space:]*$", $postedString) ) {
$b = TRUE;
} else {
	$b = FALSE;
	$content .= "<p>Letters, numbers, whitespaces, underscores, or hyphens only please.</p>\n";
}

Link to comment
https://forums.phpfreaks.com/topic/165003-solved-help-with-reg-expression/
Share on other sites

Ryan, I would recommend ditching ereg and learn PCRE instead. ereg (part of POSIX) is considered depreciated as of PHP 5.3 and will not be included within the core of version 6.

 

if(preg_match('#^[a-z0-9_\s-]*$#i', $postedString)){
...

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.