View Full Version : Regular expression

06-16-2009, 11:58 AM
Hi All,

I want regular expression for the following criteria
Contain eight characters or more
Contain characters from two of the following three character classes:
1. Alphabetic (e.g., a-z, A-Z)
2. Numeric (i.e. 0-9)
3. Punctuation and other characters (e.g., !@#$%^&*()_+|~-=\`{}[]:";'<>?,./)

Please send reply as soon as possible

Philip M
06-16-2009, 12:43 PM
Please send reply as soon as possible

What did you last servant die of? :(

It is not too practical to combine your conditions (two out of three) into just one regular expression.

I interpret Contain characters to mean contains at least one character from two of the three categories you mention.

<script type = "text/javascript">
var str = "abc123_?&@"
var flag = 0;
var len = str.length;
if (/[a-z]/gi.test(str)) {flag++}
if (/[0-9]/g.test(str)) {flag++}
if (/\W|\_/g.test(str)) {flag++}
if ((flag >=2) && (len>=8)) {
alert ("Password " + str + " meets the criteria and is valid");
else {
alert ("Invalid password!");

It has been mentioned recently in this forum that the security of a password is much more sensitive to its length than to the inclusion of numbers and/or punctuation. In other words 9 alpha-numeric characters is more secure (harder to crack) than 8 characters from the full range of alpha-numeric and punctuation. Just a thought.

"We have created a window of opportunity and it is time to walk through that window." - Local politician

06-16-2009, 01:18 PM
Thanx Philip
It is working actually that was client requirement I will consider your suggestions for next development

Philip M
06-16-2009, 01:32 PM
The problem with passwords such as xG5%uLm7 is that no-one can remember them, so they tend to be written down on a piece of paper under the mousemat.

For myself, I prefer long but semi-meaningful passwords which can be remembered, using two unrelated words (perhaps in a foreign language) separated by a digit or two.


I believe that such a 14+ character password cannot be broken in under thousands or millions of years.