Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regular expression with special characters

Posted on 2011-09-29
4
Medium Priority
?
338 Views
Last Modified: 2012-05-12
Hello,

I want to use a regular expression to validate a password. The password must meet the next requirements:
1. at least 8 characters
2. at least one digit
3. at least one character of the set  !@#$%&+{}[]:;<>?/\

What is the regular expression for these requirements?

Regards Arne
0
Comment
Question by:adiemeer
4 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 36813332
It may be simpler to use 3 separate regular expressions for each of the requirements, but if your regular expression notation supports lookahead, you might test all 3 with
(?=.{8})(?=.*\d).*[!@#$%&+{}\[\]:;<>?/\\]
0
 
LVL 4

Expert Comment

by:rbride
ID: 36813340
I'd use three separate expressions, to put it into 1 is quite tricky and not worth the effort because it is hard to maintain. Here I have used perl style.

# Match at least 8 non-space characters. After the comma you can also put in the maximum length allowed, e.g. {8,20}
($pw =~ /\S{8,}/)

# At least one digit
($pw =~ /\d+/)

# and match at least one of the special characters. Note you will have to escape certain characters (done here with backslash).
($pw =~ /[!@#\$%&+{}\[\]:;<>?\\\/]+/)
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36813443
^.*(?=.{8,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$


look for which chars needs to be escaped in your language.

HTH. Bye!
0
 

Author Closing Comment

by:adiemeer
ID: 36813511
Thanks, this works fine!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…

810 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