I have an input field. I need the input to have the following format:
AC-123456789
- First character can either be A or B in uppercase
- Second character can be any uppercase letter or number
- There has to be a hyphen after the second character
- After the hyphen there can be any number of characters between 1 and 9
I would like for the check to happen onKeyPress (in React). So if the first character is not right it will return an alerto of some kind. If the second character is not correct then I get another error. So on.
Right now my regex looks like this:
/^[A,B][A-Z0-9]-d{1,9}$/.test(value)
But this only checks once the whole input is the correct format and not after each single character is inputed in the field.