Re: PHP preg_match question

2011-07-21 Thread keith smith
Thank you all for your help!!  You suggestions solve my problem! Keith Smith --- On Wed, 7/20/11, Kevin Brown wrote: From: Kevin Brown Subject: Re: PHP preg_match question To: "Main PLUG discussion list" Date: Wednesday, July 20, 2011, 10:44 PM Another

Re: PHP preg_match question

2011-07-20 Thread Kevin Brown
Another way would be if ($vaidateStr == preg_replace("/[^a-z0-9\-]/i", "", $vaidateStr)) { /true, or valid... } the "i" after the last / makes it case insensitive. So it should match upper and lower alpha characters. Ah yes, I also forgot the uppercase chars if ($vaidateStr ==

Re: PHP preg_match question

2011-07-20 Thread Ben Trussell
Ah yes, I also forgot the uppercase chars if ($vaidateStr == preg_replace("/[^a-zA-Z0-9\-]/", "", $vaidateStr)) { /true, or valid... } BTW also as Eric says, the carrot (^) inside the square brackets means "anything but" (negation), thus how this works.. Ben On Wed, Jul 20, 2011

Re: PHP preg_match question

2011-07-20 Thread Matt Graham
From: keith smith > I have an input string that should only be lower or upper alphas, > numbers and can contain a hyphen. I'm trying to figure out how > to get PHP preg_match to verify the input string only contains these > chars. > preg_match("/[a-z0-9\+\-]/", $vaidateStr) http://crow202.org/

Re: PHP preg_match question

2011-07-20 Thread Eric Cope
Here is the regular expression: /^[a-zA-Z0-9\-]+$/ the ^ requires the pattern match at the beginning of the string. The + requires at least one of these characters, but no upper limit. You can use * if you don't need the lower limit of 1. $ requires the patten match all the way to the end of the

Re: PHP preg_match question

2011-07-20 Thread Ben Trussell
Possibly: $vaidateStr = "this is a test 1"; // not valid, contains spaces.. $compared = preg_replace("/[^a-z0-9\+\-]/", "", $vaidateStr); $is_validated = $vaidateStr == $compared; if ($is_validated) { echo "valid\n"; } else { echo "not valid\n"; } // /

PHP preg_match question

2011-07-20 Thread keith smith
Hi,  I have an input string that should only be lower or upper alphas, numbers and can contain a hyphen.  I'm trying to figure out how to get PHP preg_match to verify the input string only contains these chars. I tried some thing like this and it always returns true if I have one or more o