[Javascript] Regarding Password Validation

David Lovering dlovering at gazos.com
Mon Mar 1 08:59:54 CST 2004


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
>
>





More information about the Javascript mailing list