Stirling <> writes:
> I am looking to do a password validation check using client side
> validation. Minimum requirement is that it must contain at least one
> number and one letter.
> I have came up with the following regEx
>
> ^(\w*(?=\w+\d+)(?=\w*[a-zA-Z])\w*)$
The matches a sequence of word-characters (a requirement you didn't
mention?) that contains at least one digit(!) after a word character,
and at least one letter. The reason you don't match "1password" is
the first + in (?=\w+\d+).
A simpler version could be:
/^(?=\w*\d)(?=\w*[A-Z])\w{6,20}$/i
Still, you are relying on lookahead, which only exists in newer
browsers, and which IIRC is broken in IE. In many cases, making
more than one test is much simpler than trying to encode everything
into one RegExp.
function testPasswd(pw) {
return /[a-z]/i.test(pw) && /\d/.test(pw) && /^\w{6,20}*$/.test(pw);
}
> This works fine in IE but when testing it using NS6 it won't validate
> '1password', but will validate 'password1'.
That supports my recollection that lookahead in IE is broken, because
it should not match "1password".
> It seems the first forward search is consuming the first character
> in NS, would this be correct,
Yes, because you asked it to.
/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'