Solved

# Regular Expression Question

Posted on 2012-03-31
288 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
Question by:prain
5 Comments

LVL 20

Expert Comment

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

LVL 74

Accepted Solution

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

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

LVL 74

Expert Comment

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,}\$
``````

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

LVL 2

Expert Comment

ID: 37792589
0

Author Closing Comment

ID: 37833305
Thanks
0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!