I am trying to find the correct RegEx pattern to allow one or two letters followed by 3 to 5 numbers and optional One letter at the end. Finally non-alphanumeric should be allowed to wrap the string:
Allowed
M394
,MP4245)
TD493!
X4958A
V49534@
U394U
A5909.
Not Allowed
TED492
R32
R4!3
U394UU
A5909AA
5349A
I found an example but it does not quite work:
RegEx pattern any two letters followed by six numbers
Thanks for your help
You can use this regex:
\b[a-zA-Z]{1,2}\d{3,5}[a-zA-Z]?\b
RegEx Demo
Breakup of regex
\b # word boundary
[a-zA-Z]{1,2} # 1 or 2 letters
\d{3,5} # 3 to 5 digits
[a-zA-Z]? # an optional letter
\b # word boundary
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