Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular Expression Question

Posted on 2012-03-31
5
Medium Priority
?
298 Views
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.


prain
0
Comment
Question by:prain
5 Comments
 
LVL 20

Expert Comment

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

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 600 total points
ID: 37791074
Try:

^(?=\D*\d)(?=[^a-zA-Z]*[a-zA-Z])(?!.*(.)\1).{8,}$

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37791130
P.S.

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
^(?=\D*\d)(?=[^a-zA-Z]*[a-zA-Z])(?!.*(.)\1)[a-zA-Z0-9]{8,}$

Open in new window


Restrict to Letters and Numbers and a Few Special Characters
^(?=\D*\d)(?=[^a-zA-Z]*[a-zA-Z])(?!.*(.)\1)[a-zA-Z0-9$#@!]{8,}$

Open in new window

0
 
LVL 2

Expert Comment

by:Codecaesar
ID: 37792589
0
 

Author Closing Comment

by:prain
ID: 37833305
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

876 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