Solved

Regular expression with special characters

Posted on 2011-09-29
4
332 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 500 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

Independent Software Vendors: 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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…

695 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