Regular Expression Question

Posted on 2012-03-31
Last Modified: 2012-04-11
How to make this password reg,. ex. I have had enough problems with this.

*Must contain at least 8 characters.
*Must include a number and a letter.
*No more than two consecutive characters may be the same.

Question by:prain
LVL 20

Expert Comment

ID: 37791000
$x =~ /.{8}/ && $x =~ /[a-zA-Z]/ && $x =~ /[0-9]/ && !($x =~ /(.)\1\1/)

Open in new window

LVL 75

Accepted Solution

käµfm³d   👽 earned 150 total points
ID: 37791074


Open in new window

LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37791130

I urge you to define your password requirement a bit further. I fashioned the above strictly by the rules you posted. However, the use of the dot allows for even non-printable characters to be used as a part of the password. This means null characters, spaces, newlines, percent signs...  pretty much any character can be used as a part of the password--so long as there are 8 of them. It should be as simple as changing the ".{8,}" part of the pattern to provide further restrictions. For example:

Restrict to Letters and Numbers

Open in new window

Restrict to Letters and Numbers and a Few Special Characters

Open in new window


Expert Comment

ID: 37792589

Author Closing Comment

ID: 37833305

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 86
Regular Expression to find a line feed 1 38 mvc return json 2 56
Interview question Javascript, database 12 33
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now