JeroenE
JeroenE

Reputation: 703

Regex with min 8 digits, 20 characters

I'm currently looking for a regex that verify's the following requirements:

example:

12345678: true
123adafa45678: true
123ab456: false (needs atleast 8 digits, now only 6)
ab12345a678: true 
ab123456789afgb2459a2: false (more then 20 characters)

I tried serveral things but if I use something like: (\D*\d\D*){8,} then it works but it doesn't meet the last requirement (up to 20 characters).

Upvotes: 2

Views: 2206

Answers (1)

Bohemian
Bohemian

Reputation: 424953

Use a lookahead for 8 digits:

^(?=(.*\d){8})[a-zA-Z\d]{8,20}$

See live demo.

Upvotes: 2

Related Questions