javascript - What would be the regex for matching an alphanumeric string with 4 digits & 1 alphabet? -


for example, should allow strings '1234n' , '1234a' . max string size 5 , should allow sequence of 4 digits followed character.

you can do:

^\d{4}[a-za-z]$ 
  • ^\d{4} matches 4 digits @ start

  • [a-za-z]$ matches single alphabetic character @ end