OyeHarish
OyeHarish

Reputation: 320

Regular Expression for atleast one character and one number with no repeat more than two

I am trying one of regular expression for condition like:

atleast 1 number, atleast 1 character, should be 3 to 16 digit long. No character and number should repeat more than 2 time.

I tried one regular expression here what i tried.

(^(?=.*\d)(?=.*[a-zA-Z]).{3,16}$)\1{2,}

but it did not do the trick.

example for valid and invalid post:

Upvotes: 1

Views: 126

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626747

You can try using this regex (edited to fail strings that have triple consecutive symbols):

^(?=.*[0-9])(?=.*[a-zA-Z])(?!.*(.)\1\1.*).{3,16}$

See example here.

Upvotes: 2

Related Questions