?
Solved

regular expression - password policy enforcement

Posted on 2010-08-24
6
Medium Priority
?
553 Views
Last Modified: 2012-05-10
Hello Experts,

I need a regular expression string that matches (1 capitol, 1 lowercase, 1 number, 1 special character)

I had this:
\A(?=[-@!$^*()~_a-zA-Z0-9]*?[A-Z])(?=[-@!$^*()~_a-zA-Z0-9]*?[a-z])(?=[-@!$^*()~_a-zA-Z0-9]*?[0-9])[-@!$^*()~_a-zA-Z0-9]{8,16}\z

which seemed to be working until I added the '#' character to the string at which point it quits. Unfortunately this problem got missed until about a week away from production so I am reaching out...

Any help appreciated!
I am using this expression with the PCRE engine.
0
Comment
Question by:glo-dba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 20

Accepted Solution

by:
alainbryden earned 2000 total points
ID: 33510079
This regular expression seems to have everything you need. If you don't require at least 10 characters you can remove that first part:
http://davidhayden.com/blog/dave/archive/2004/09/25/501.aspx

^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

    * Must be at least 10 characters
    * Must contain at least one one lower case letter, one upper case letter, one digit and one special character
    * Valid special characters (which are configurable) are -   @#$%^&+=

--
Alain
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 33510106
Well it looks like your problem might be that in the PCRE documentation, comments are delimited by the # mark. Maybe you need to escape it by using it twice? (##)
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 33510120
I stand corrected, apparently using \# to escape the hash character should take care of it.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:alainbryden
ID: 33510133
Here's the man page for your reference: http://www.pcre.org/pcre.txt
The relevant section for the # problem has the header "BACKSLASH"
0
 
LVL 3

Expert Comment

by:gremwell
ID: 33510198
By the way, you may also want to escape $ sign, otherwise Perl will expand $^ variable.
0
 

Author Closing Comment

by:glo-dba
ID: 33542841
Your string works fine. My string doesn't work. It may be may an inconsistency in the "regex buddy" PRCE engine.

Thank you very much!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

801 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