[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Regular expression with special characters

Posted on 2011-09-29
4
Medium Priority
?
336 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
[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 Comments
 
LVL 84

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
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

656 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