Reputation: 217
I'd like to make an regular expression that check in a string that match at least 8 digits and exactly 2 characters in uppercase. the letters and decimals can be anywhere.
Thanks
Upvotes: 1
Views: 1217
Reputation: 76000
Would this work:
^(?=[A-Z0-9]{10,})\d*[A-Z]\d*[A-Z]\d*$
^
- Match start of string(?=[A-Z0-9]{10,})
- A positive LookAhead to match at least 10 chars from [A-Z0-9]
only\d*[A-Z]\d*[A-Z]\d*
- Two chars in the range [A-Z]
surrounded by zero or more digits$
- Match end of stringAlternatively, create another capture group:
^(?=[A-Z0-9]{10,})(\d*[A-Z]){2}\d*$
Now you got a little bit more flexibility to tell the pattern you need an x-amount of upper case letters > {x}
Upvotes: 5