Re: Regular expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!
...........................................................

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux