Jay
Jay

Reputation: 322

Javascript password validation

I've a pretty good password validation, but I would like to add some more functionality.

You can see an example here http://jsfiddle.net/yfM5T/22/

Currently I've a password that checks, 7 chars, 1 upper case, 1 digit and 1 special character and even it won't allow white space.

But I want to add

  1. password doesn't contains 9 consecutive numbers (because some people use phone numbers as passwords, e.g. it won't take Pass@123456789 but Pass123456@789 is ok)
  2. Not same as the log-in name
  3. Not more than two repeating characters (saaga is ok but saaaga is not allowed)

Bonus if the password validation tool tip shows the white space validation message only if the user put a white space rather than showing onfocus (only for the white space, 9 consequtive numbers, username etc.)

Upvotes: 1

Views: 1543

Answers (1)

FailedDev
FailedDev

Reputation: 26920

  • 1) ^(?!.*\d{9}.*)
  • 3) ^(?!.*([a-zA-Z])\1\1)

For the second rule just use a string comparison with the username.

Upvotes: 2

Related Questions