Re: Regular expressions

From: Date: Wed, 12 Dec 2007 07:04:37 +0000
Subject: Re: Regular expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-265743@lists.php.net to get a copy of this message
On Tue, 2007-12-11 at 22:33 -0800, Liz Kim wrote: > I am trying to do a password match with php.. > > It needs to be at least 6 characters, contains 2 alphabets and at least 1 > number or a special character... > > if > > (!preg_match("/^.*(?=.{6,})((?=.*\d)|(?=.*[,\=@\"\/'+\*\?\.\[\]\^$\(\){}\|\\&:;'<>~`#%_-]))([a-zA-Z]{2,}).*$/", > $pw1)) {error message} > > is failing to pass "e1w2qw" as a good password although it follows the > instructions... > > I cannot figure out why.. Any reason you took such a complex route? <?php if( strlen( $pw1 ) < 6 || !ereg( '[[:digit:]]', $pw1 ) || strlen( ereg_replace( '[^[:alpha:]]', '', $pw1 ) ) < 2 || strlen( ereg_replace( '[[:alnum:][:space:]]', '', $pw1 ) ) < 1 ) { // error message } ?> Cheers, Rob. -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ...........................................................

« previous php.general (#265743) next »