In your template, the pipe makes the first part of it coincide with either AB or an empty string. You have not excluded two characters from 17, so it must match an empty string to get the next 17 characters according to the rest of the pattern. The pattern will also match, for example, AB00000000000000000 , i.e. AB followed by 17 alphanumeric characters.
You must do this according to the combinations of two characters at the beginning, then 15 alphanumeric characters:
^(AB|DE|GH)[a-zA-Z0-9]{15}$
Guffa source share