[thelist] regex help - password pattern - javascript

Kowalkowski, Lee (ASPIRE) lee.kowalkowski at hmrcaspire.com
Tue Sep 27 03:57:43 CDT 2005


> -----Original Message-----
> From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
> Sent: Monday, September 26, 2005 10:45 PM
> To: Anthony Ettinger; thelist
> Subject: Re: [thelist] regex help - password pattern - javascript
> 
> I must not have been clear, requirements are:
> 
> - MINIMUM of 8 characters in length (can be longer)
> - 2 digits REQUIRED (anywhere in string)
> - 2 alpha REQUIRED (anywhere in string)
> 

I'm not sure why you're trying to solve this with 1 regular expression.  If
you have the three rules above, you ought to have three conditions in your
code.  That way you have the opportunity to provide more guidance in your
error messages.  Rather than an unhelpful "invalid password" message, tell
the user exactly why.

I wouldn't bother with a regular expression for the first rule, just check
password.length.  If you don't allow leading, trailing or any whitespace,
write a separate condition for that.

The second rule: /(.*\d){2}/.test(password)

The third rule: /(.*[a-z]){2}/i.test(password)

- LK


===========================================================
Our e-mail domain has now changed from iraspire.com to hmrcaspire.com. Please update your address books.
===========================================================



More information about the thelist mailing list