-4

I need REGEXP for alpha Numeric zip code, which contains minimum 3 & maximum 10 values.

  • Invalid inputs are: AAAAA, A1, AA, 12, 2A
  • Valid inputs are: 123456, 123, A1234, A12, A12A, A9A

This is the regex I'm currently using:

/(^[A-z0-9]\d{3,10})+$/

It doesn't allow to specify only digits like this 12345 but input like A123 matches correctly.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Mahesh Kalyankar
  • 107
  • 1
  • 1
  • 13

1 Answers1

0

The question is not completely clear. If you mean that you can use between 3 and 10 characters, and these characters can be alphanumerical characters (digits and [A-Za-z]), you can use:

/^(?=.*\d.*)[A-Za-z0-9]{3,10}$/

regex101 demo.

The regex works as follows:

  • ^[A-Za-z0-9]{3,10}$ says the regex consists out of 3 to 10 characters that can be digits and/or A-Z/a-z.
  • The lookahead (?=.*\d.*) enfoces that the string contains at least one digit somewhere in the string.
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555