[Javascript] Regarding Password Validation

David Lovering dlovering at gazos.com
Mon Mar 8 15:48:07 CST 2004


Looks good.  Not nearly as gruesome as I imagined it might be.

I'll have to check all the syntax variants, but if this works for the
customer, it should be SWEET!

-- Dave Lovering

----- Original Message ----- 
From: "Håkan Magnusson" <hakan at backbase.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Monday, March 08, 2004 3:45 AM
Subject: Re: [Javascript] Regarding Password Validation


> I'm sorry for the delay, it's been a busy week. However, I did some
> polishing and finished it up, and I think this is the regexp you are
> looking for:
>
> //--
> var rxPassword = new
> RegExp(/(([\d].*[\d].*[^\w])|([^\w].*[\d].*[\d])|([\d].*[^\w].*[\d]))+/);
> var sPassword = new String();
>
> sPassword = 'bhf97ax'; // Should be false, missing special character
> alert('Should be false: ' + rxPassword.test(sPassword));
>
> sPassword = '6list!'; // Should be false, not enough numbers
> alert('Should be false: ' + rxPassword.test(sPassword));
>
> sPassword = '!!AN6RY!!'; // Should be false, not enough numbers
> alert('Should be false: ' + rxPassword.test(sPassword));
>
> sPassword = 'i:rt66'; // Should be true
> alert('Should be true: ' + rxPassword.test(sPassword));
>
> sPassword = '9!9opa<'; // Should be true
> alert('Should be true: ' + rxPassword.test(sPassword));
>
> sPassword = '=7ddd7'; // Should be true
> alert('Should be true: ' + rxPassword.test(sPassword));
> //--
>
> Make sure that the RegExp declaration is all on one line, I'm afraid
> mail viewers might break it since it's pretty long. :) If I find ways to
> optimize it further, I'll let you know.
>
> Regards,
> H
>
>
> Ramachandran wrote:
> > Hi Hakan,
> >
> > Yes i really need the Regular Expression for these conditions. If u find
> > time...please write and send it to me...
> >
> >
> >
> > -----Original Message-----
> > From: javascript-bounces at LaTech.edu
> > [mailto:javascript-bounces at LaTech.edu]On Behalf Of Hakan Magnusson
> > Sent: Monday, March 01, 2004 9:06 PM
> > To: [JavaScript List]
> > Subject: Re: [Javascript] Regarding Password Validation
> >
> >
> > Ramachandran,
> > This could be accomplished with only one regexp, of course.
> >
> > My regexp skills are not quite up to date, but something that vaugely
> > resembles this line should probably work:
> >
> > /[0-9]{2,}[^a-zA-Z0-9]{1,}/
> >
> > You can then test your password field value against the regexp, and it
> > will return true if the password has at least two numbers and one
> > special character.
> >
> > Again, my regexp skills are not very hot. Someone who do know the ins
> > and outs of regexps can build this for you in the blink of an eye, this
> > regexp is NOT complicated. If you really need me to, I can build it for
> > you when I have the time.
> >
> > Dave,
> > I don't know about 'missing 80% of the power of JavaScript', regexps
> > have nothing to do with JavaScript. Saying that someone who doesn't know
> > regexps are missing 80% of the power of string manipulation/testing
> > sounds more accurate to me. ;)
> >
> > H
> >
> >
> > David Lovering wrote:
> >
> >
> >>The easiest way I can think of is to use two regular expression filters
to
> >>strip (respectively) everything out EXCEPT numbers, and everything out
> >>EXCEPT special characters.  The output of these two filters are put into
> >
> > two
> >
> >>strings, such as
> >>
> >>var digitString;
> >>var specialString;
> >>
> >>... and then simply check the length of the two strings to make sure
that
> >>they are greater than or equal to 2 and 1, again respectively.
> >>
> >>If you're not up on regular expression filters, you're missing about 80%
> >
> > of
> >
> >>the power of JavaScript (at least IMO).
> >>
> >>Try
> >>
> >>  var re0 = /[^0-9]/g;
> >>  var re1 = /[a-zA-Z0-9]/g;
> >>
> >>  var digitString = myString.replace(re0, "");
> >>  var specialString = myString.replace(re1, "");
> >>
> >>  alert("number of digits: " + digitString.length);
> >>  alert("number of special characters: " + specialString.length);
> >>
> >>Or some variation thereof.  Incidently, I'd also check myString (the
> >
> > target
> >
> >>string coming in) for total length as well, as short strings are easy to
> >>crack.
> >>
> >>-- Dave Lovering
> >>----- Original Message -----
> >>From: "Ramachandran" <ramachandran at summitworks.com>
> >>To: "[JavaScript List]" <javascript at LaTech.edu>
> >>Sent: Monday, March 01, 2004 6:42 AM
> >>Subject: [Javascript] Regarding Password Validation
> >>
> >>
> >>
> >>
> >>>Hi all,
> >>>
> >>>I want to perform a validation in password field. The validation
includes
> >>>the following conditions.
> >>>
> >>>1. It should contain atleast two no.s and once special characters.
> >>>
> >>>How can i do this one..
> >>>
> >>>Regards,
> >>>Ram
> >>>
> >>>_______________________________________________
> >>>Javascript mailing list
> >>>Javascript at LaTech.edu
> >>>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>>
> >>>
> >>
> >>
> >>
> >>_______________________________________________
> >>Javascript mailing list
> >>Javascript at LaTech.edu
> >>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>
> >>
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> >
>
>
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list