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?

4

2 回答 2

0

好的,玩了一会儿之后,这是解决方案:

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])).+$)/
于 2013-04-18T11:45:10.077 回答
-2

这是一个在 javascript 中具有密码验证程序的网站:

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

于 2013-04-17T11:53:50.347 回答