0

I need to validate (and confirm) a new password on a site. There are criteria I need to test for, and I'm looking for the best method to do so, using jQuery.

The criteria are:

  1. Must have a minimum of 8 characters and a maximum of 12
  2. Should have at least three of the following: A. Upper case letter; B. Lower case letter; C. Numeric character; D. Punctuation.

EDIT: The following regexp is what I'm currently using to accomplish this.

regexp/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/

However, that checks to make sure that all four of those types are present, when I need only three out of the four (and it doesn't matter which three.) Can anyone suggest how to improve my regex to accomplish this?

UPDATE: I've still not figured out how to accomplish this, but have thought of a few scenarios. The way I see it is that it should be done using 5 permutations, and using AND and OR operators. However, I don't know how to do that in regex. Am I barking up the wrong tree?

10
  • jQUery won't help you to validate the ruleset, but you can retrieve the value of the password field with it. What part do you need help with? (retrieving the field content & displaying the result or validating rules?)
    – DThought
    Commented Apr 17, 2013 at 11:46
  • Relevant: security.stackexchange.com/questions/6287/…
    – JJJ
    Commented Apr 17, 2013 at 11:47
  • 1
    Didnt show any effort from your side Commented Apr 17, 2013 at 11:50
  • no one is here to write code for you, we're here to help Commented Apr 17, 2013 at 11:56
  • I apologize if I come across that way. I never intended for anyone to write anything for me, but only to recommend a particular plugin, if one is available.
    – dihakz
    Commented Apr 17, 2013 at 12:07

2 Answers 2

0

Okay, after playing around a bit, here is the solution:

regexp/(^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$)|(^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$)|(^(?=.*[a-z])(?=.*[A-Z])(?=.*(_|[^\w])).+$)|(^(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$)|(^(?=.*[a-z])(?=.*\d)(?=.*(_|[^\w])).+$)/
-2

Here's a website which has a password validation program in javascript:

http://www.javascriptsource.com/forms/val-pass.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.