Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Password Regular Expression

Reply
Thread Tools

Password Regular Expression

 
 
Stirling
Guest
Posts: n/a
 
      05-15-2004
Hi all,
hope someone can help me,

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. (Ideally it would be of 6-20 characters in
length but first things first).

I have came up with the following regEx

^(\w*(?=\w+\d+)(?=\w*[a-zA-Z])\w*)$

This works fine in IE but when testing it using NS6 it won't validate
'1password', but will validate 'password1'. It seems the first forward
search is consuming the first character in NS, would this be correct,
and if so can anybody suggest either a way arround this or a different
regular expression,

Thanks in advance,

SJM.

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-15-2004
Stirling wrote on 15 mei 2004 in comp.lang.javascript:

> 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. (Ideally it would be of 6-20 characters in
> length but first things first).
>
> I have came up with the following regEx
>
> ^(\w*(?=\w+\d+)(?=\w*[a-zA-Z])\w*)$
>
> This works fine in IE but when testing it using NS6 it won't validate
> '1password', but will validate 'password1'. It seems the first forward
> search is consuming the first character in NS, would this be correct,
> and if so can anybody suggest either a way arround this or a different
> regular expression,
>


function pwTest(w){
t1 = /^[a-z\d]{6,20}$/i // only and length
t2 = /[a-z]/i // at least 1 letter
t3 = /\d/ // at least 1 number

return t1.test(w) && t2.test(w) && t3.test(w)
}


alert(pwTest("1qweqweasd"))


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Ivo
Guest
Posts: n/a
 
      05-15-2004
"Stirling" wrote
> 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. (Ideally it would be of 6-20 characters in
> length but first things first).
> <snip>


Lookahead regexes are not very widely supported. Look at this:

var pword='djuhy9dgyg';
alert( /[a-z]/i.test( pword ) && /\d/.test( pword ) && /.{6,20}/.test(
pword ) )
// alerts true or false

Three little regexes may not be the most efficient way, but would be fast
enough for me.
Ivo


 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      05-15-2004
Stirling <(E-Mail Removed)> 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 - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Stirling
Guest
Posts: n/a
 
      05-16-2004
Evertjan. wrote:

> Stirling wrote on 15 mei 2004 in comp.lang.javascript:
>
>
>>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. (Ideally it would be of 6-20 characters in
>>length but first things first).
>>
>>I have came up with the following regEx
>>
>>^(\w*(?=\w+\d+)(?=\w*[a-zA-Z])\w*)$
>>
>>This works fine in IE but when testing it using NS6 it won't validate
>>'1password', but will validate 'password1'. It seems the first forward
>>search is consuming the first character in NS, would this be correct,
>>and if so can anybody suggest either a way arround this or a different
>>regular expression,
>>

>
>
> function pwTest(w){
> t1 = /^[a-z\d]{6,20}$/i // only and length
> t2 = /[a-z]/i // at least 1 letter
> t3 = /\d/ // at least 1 number
>
> return t1.test(w) && t2.test(w) && t3.test(w)
> }
>
>
> alert(pwTest("1qweqweasd"))
>
>

My problem is that I am using ASP.net validation, so it must consist of
a singe validation expression. Is there any other way of doing this
sirt of thing with a single expression without looking forward?

SJM.

 
Reply With Quote
 
Stirling
Guest
Posts: n/a
 
      05-16-2004
Richard Cornford wrote:
> Evertjan. wrote:
>
>>Stirling wrote:

>
> <snip>
>
>>>My problem is that I am using ASP.net validation, so it must consist
>>>of a singe validation expression. Is there any other way of doing
>>>this sirt of thing with a single expression without looking forward?

>>
>>This once more convinces me to stick to classical ASP.
>>
>>Either you are wrong or ASP-net stinks.

>
>
> It does seem unlikely that ASP-net would impose such an arbitrary
> restriction, but an expression could be a function call or a function
> expression (that was called as - (function(){ ... })() -) so even with
> this restriction there would be no limit on the amount of javascript
> executed to resolve one expression.
>
> Richard.
>
>

What I am using is the Validation controls which are part of the ASP.net
framework (actullay I'm using a modified version called the
DOMValidators.) These controls attach to a Textbox, and allow a regular
expression match against the text box. Yes it is limiting, but it
reduces the amount of javascript that needs coded quite a lot. So I'm
stuck with using a single validation string.

S.

 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      05-17-2004
Stirling wrote on 16 mei 2004 in comp.lang.javascript:
>> function pwTest(w){
>> t1 = /^[a-z\d]{6,20}$/i // only and length
>> t2 = /[a-z]/i // at least 1 letter
>> t3 = /\d/ // at least 1 number
>>
>> return t1.test(w) && t2.test(w) && t3.test(w)
>> }
>>
>>
>> alert(pwTest("1qweqweasd"))
>>
>>

> My problem is that I am using ASP.net validation, so it must consist of
> a singe validation expression. Is there any other way of doing this
> sirt of thing with a single expression without looking forward?


This once more convinces me to stick to classical ASP.

Either you are wrong or ASP-net stinks.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      05-18-2004
Evertjan. wrote:
> Stirling wrote:

<snip>
>> My problem is that I am using ASP.net validation, so it must consist
>> of a singe validation expression. Is there any other way of doing
>> this sirt of thing with a single expression without looking forward?

>
> This once more convinces me to stick to classical ASP.
>
> Either you are wrong or ASP-net stinks.


It does seem unlikely that ASP-net would impose such an arbitrary
restriction, but an expression could be a function call or a function
expression (that was called as - (function(){ ... })() -) so even with
this restriction there would be no limit on the amount of javascript
executed to resolve one expression.

Richard.


 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      05-19-2004
On Tue, 18 May 2004 19:06:10 +0100, "Richard Cornford"
<(E-Mail Removed)> wrote:

>Evertjan. wrote:
>> Either you are wrong or ASP-net stinks.

>
>It does seem unlikely that ASP-net would impose such an arbitrary
>restriction,


It's entirely possible ASP.NET webforms stink, no seriously, they
really stink. They are almost certainly the worst thing ever to come
out of Microsoft.

> but an expression could be a function call or a function
>expression (that was called as - (function(){ ... })() -) so even with
>this restriction there would be no limit on the amount of javascript
>executed to resolve one expression.


True, but stop shining the shite, there's no way it'll be worth it.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      05-21-2004
Jim Ley wrote:
> "Richard Cornford" wrote:
>>Evertjan. wrote:
>>> Either you are wrong or ASP-net stinks.

>>
>>It does seem unlikely that ASP-net would impose such an
>>arbitrary restriction,

>
> It's entirely possible ASP.NET webforms stink, no seriously,
> they really stink. They are almost certainly the worst thing
> ever to come out of Microsoft.

<snip>

I am not sure why I gave Microsoft credit for not being that stupid,
they demonstrate monumental incompetence on occasions, like the fact
that I have to use a Mozilla/Gecko browser when I visit the MSDN site
because they cannot cope with the configurability of their own (IE6)
browser.

Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments