Mladen Branković
Mladen Branković

Reputation: 1

RegExp pass validation

Start with letter, at least one upper and lower case characters, at least one digit, 6-12 charachers, and no more then 3 consecutive same characters

I write this, but not good enough.. .Any ideas?

/^[A-Za-z] (?=.*\d) (?=.*[a-z])(?!.*(.)\1\1)(?=.*[A-Z]).{6,12}$/

Upvotes: 0

Views: 83

Answers (1)

Thomas Ayoub
Thomas Ayoub

Reputation: 29431

You can use:

^(?=^[A-Za-z])(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*(.)\1\1).{6,12}$
  • (?=^[A-Za-z]) starts with a letter
  • (?=.*\d) contains a number
  • (?=.*[a-z]) contains lower case letter
  • (?=.*[A-Z]) contains UPPER case letter
  • (?!.*(.)\1\1) not 3 consecutive char
  • .{6,12} from 6 to 12 long

Upvotes: 2

Related Questions