I’m trying to figure out a regex for this rule:
“Must contain minimum 3 and maximum 5
numeric chars. The same character can
be repeated max. 5 times! Also, the length should be minim 10 chars.”
Do you have any ideea?
I started with this:
^\d{3,5}$
but this does restrict to have min. 3 decimals one after other and what I need is the possibility to have them intercalated with letters also (min. 3 and max 5 occurrences).
Can you give a helping hand please?
It’s possible in regex, but the need of backreference is going to make it very slow.
Description:
(?=(?:\D*\d){3,5}\D*$): Ensure there is 3 to 5 numerals(?!.*(.)(?:.*\1){4}): Ensure there is not 5 copies on the same character.{10,}: Ensure the matched string’s length is at least 10.An easier way is to use a
Dictionary<char, int>and tally the characters.