Re: Regular Expresson for checking password strength
| From: | Al | Date: | Fri, 04 Aug 2006 20:46:22 +0000 |
| Subject: | Re: Regular Expresson for checking password strength | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240155@lists.php.net to get a copy of this message | ||
Adam Zey wrote:
Al wrote:You are correct on both counts. Getting the strlen() first will save about .01usec.James Nunnerley wrote:Some mistakes there: 1) You want to assign strlen to a variable before the if, since you're calling it twice in the if. I'm not certain how fast strlen is, but it's usually a bad idea to repeat useless function calls like that. 2) Isn't your second function call supposed to be preg_match, and not pre_match? Regards, Adam Zey.I want to have a regular expression that check the following criteria are met by $password: - contains at least 6 characters (any) - has at least 1 letter - has at least 1 number - other 6 characters can be anything... I'm happy to work out the structure of a postcode etc, but to be honest I'm still fairly new to working with regular expressions. What the best/easiest way to check whether a variable contains a range? It might be RegExp don't do this? Cheers NunnersIt can be done; but, it's simpler to simply to make an if() with (strlen($password) > 5) && (strlen($password) < max) && pre_match("%[a-z]+%i"%, $password) && preg_match("%\d+%", $password)