user3750290 user3750290 - 3 months ago 13
Javascript Question

Regular Expression search to search exact match

I am very much new to regex.

I have a scenario where I need to check the textbox value to the below format:

Format: AZnnnnnnn-nnn

The value has to start with "AZ" followed by 7 numerics and -(hiphen) and followed by 3 numerics

Can someone help on this

Answer

You can use this regex:

^AZ\d{7}-\d{3}$

^       -> start of string
AZ      -> AZ
\d      -> digit
{7}     -> exactly 7
-       -> hyphen
{3}     -> exactly 3
$       -> end of string