This didnt make it to the list earlier. Maybe I need some email lessons. Leonard. ----- Original Message ----- From: pop <[EMAIL PROTECTED]> To: Jason Paschal <[EMAIL PROTECTED]> Sent: Monday, June 02, 2003 10:58 AM Subject: Re: [PHP] zip code validation/regular expression
> Since you are only trying to match a 00000-0000 and 00000 why not add a if > statement b4 it compares the regex. I think that might be the simplest. > > Leonard > > > <?php > > $regex1 = "/^(\?(^00000(|-0000))|(\d{5}(|-\d{4})))$/"; > > $zips = > array("21243","21832-1234","00000-0000","00000","1234","ABCDEF","ABC"); > > foreach ($zips as $zip) { > if (($zip=="00000-0000") or ($zip=="00000")) > { > echo "$zip doesn't match.<br>"; > } > else > { > if (preg_match($regex1,$zip)) > { > echo "$zip MATCHES.<br>"; > } > else > { > echo "$zip doesn't match.<br>"; > } > } > > ?> > > ----- Original Message ----- > From: Jason Paschal <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, June 02, 2003 9:24 AM > Subject: [PHP] zip code validation/regular expression > > > > Simply trying to use regular expressions to validate a 5 or 5+4 zip code, > > excluding 00000 and 00000-0000. Looked on http://www.regexlib.com, and > > that's where I found the pattern below, but it doesn't work. The best I > can > > do on my own is two separate regular expressions, one to match a valid > zip, > > and another to match the 00000 invalid code. I would really like to > > condense it into one, just because I think it should be possible. > > This code below is suppose to do all this for me, but it's not matching as > > I'd hoped. I get results like this: > > > > 21832-1234 MATCHES. > > 00000-0000 MATCHES. > > 00000 MATCHES. > > 1234 doesn't match. > > ABCDEF doesn't match. > > ABC doesn't match. > > > > I'd appreciate any help. Thanks, > > jason > > > > <?php > > > > $regex1 = "/^(\?(^00000(|-0000))|(\d{5}(|-\d{4})))$/"; > > > > $zips = > > array("21243","21832-1234","00000-0000","00000","1234","ABCDEF","ABC"); > > > > foreach ($zips as $zip) { > > if (preg_match($regex1,$zip)) { > > echo "$zip MATCHES.<br>"; > > } else { > > echo "$zip doesn't match.<br>"; > > } > > } > > > > ?> > > > > _________________________________________________________________ > > MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. > > http://join.msn.com/?page=features/virus > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php