Re: Checking for characters in string
| From: | Joe Webster | Date: | Sat, 05 Jan 2002 06:41:32 +0000 |
| Subject: | Re: Checking for characters in string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-79546@lists.php.net to get a copy of this message | ||
This one had me for a min, thank god for the lookahead =)
$password_string being the password in quesiton, $is_valid = true when it is
valid, false when it's not valid.
$is_valid = preg_match("/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])./",
$password_string);
I've said it before and I'll say it again, preg is ~40x faster than
ereg/eregi and (IMO) better.
Enjoy,
Joe
"Richard Black" <rblack@datavisibility.co.uk> wrote in message
news:01C1950C.06A77AF0.rblack@datavisibility.co.uk...
>
> Hi,
>
> I'm writing a page which will allow user's to register for an online
service. They register a username and password.
>
> I want the password to contain at least one lowercase letter, at least one
upper case letter, and at least one digit. So
>
> passW0rd would be valid, but password would not.
>
> Whats the most compact way to do this? substr? ereg?
>
> Richy
>
> ==========================================
> Richard Black
> Systems Programmer, DataVisibility Ltd -
> http://www.datavisibility.com
> Tel: 0141 435 3504
> Email: rblack@datavisibility.co.uk
>