I'm trying to validate a form field in Java using Regex, which can have 5 different format possibilities. I'm struggling to get this one working.
The string to be checked will be between 4-6 alphanumeric characters.
If it's 4 characters, it must be all numbers.
^\\d{4}$
If it's 5 characters, it can be all numbers, first position letter with 4 following numbers, or first 3 positions letters followed with 2 numbers.
^\\d{5}$
^[a-zA-Z]\\d{4}$
^[a-zA-Z]{3}\\d{2}$
And if it's 6 characters, it will be first position letter, 4 numbers, and last another letter.
^[a-zA-Z]\\d{4}[a-zA-Z]$
I just can't seem to piece it all together though.