I would like to validate a string for letters A-Z, AA-ZZ, AAA-ZZZ, and so on with a regex. I know [A-Z] will validate the first case but what about the others.
A, B, C, D, E, .... Z
or
AA, BB, CC, DD, EE, .... ZZ
or
AAA, BBB, CCC, DDD, EEE, ... ZZZ
and so on...
This is a pain to write, but if you want to match any number of letters and require them to all be the same letter, you could use something like this:
^(A+|B+|C+|D+ ...)$
and so on through the rest of the alphabet.
Try
^(\w)\1*$
You match any word character. If it is more than one char, it has to be the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With