an 20 - 24 char long alphanumeric string with no spaces and no symbols that has at least 2 digits
AAAAAAAAAAAAAAAAAAAA - not valid
AAAAAA0AAAAAAAAA0AAA - valid
AAAAAA01AAAAAAAAA0AAA - valid
AAAAAA0AAAAAAAAA0AAA@ - not valid
an 20 - 24 char long alphanumeric string with no spaces and no symbols that has at least 2 digits
AAAAAAAAAAAAAAAAAAAA - not valid
AAAAAA0AAAAAAAAA0AAA - valid
AAAAAA01AAAAAAAAA0AAA - valid
AAAAAA0AAAAAAAAA0AAA@ - not valid
I think this is only possible with look-ahead assertion:
^(?=[a-zA-Z\d]{20,24}$)[a-zA-Z]*\d[a-zA-Z]*\d[a-zA-Z\d]*$
The look-ahead assertion ((?=[a-zA-Z\d]{20,24}$)
) checks if the string has the expected form (20–24 alphanumeric characters). And the second part ([a-zA-Z]*\d[a-zA-Z]*\d[a-zA-Z\d]*
) checks if it contains at least two digits.
I'm going to be abstract because this sounds like homework (if it is, please tag it as such).
{
min,
max}
[
charlist]
Update your question (& tags) if you need more help.
Basically the same idea as Gumbo just a little shorter:
^(?=[\w\d]{20,24}$)[\w]*\d[\w]*\d[\w\d]*$
Gumbo has a correct expression for the requirements.
It could be shortened, but his was more clear and probably faster than the short version.
var rX=/^(?=[a-zA-Z\d]{20,24}$)([a-zA-Z]*\d){2,}/
I think that this is the simplest pattern: First make a positive lookahead to check that there are at least two digits, then match 20-24 alphanumeric characters:
^(?=.*\d.*\d)[A-Za-z\d]{20,24}$