I need to adapt Javascript RegEx to fit specific patterns. RegEx is used in the html5 pattern attribute to validate the input field.
I want to accept only the alphanumeric template of the following types:
A-AAAA or BB-BBB (assumed pattern: 1 digit before "-" and 4 digits after "-" or 2 digits before "-" and 3 digits after "-",).
My current RegEx:
/([\w]{1,2})(-([\w]{3,4}))/g
This works, but also accepts CC-Priv, which is obviously a valid input pattern but not a targeted pattern. It also accepts DDD-DDDD; valid again but not intended.
Could you help adapt the template?
source share