How to validate this regex? AA-000

Asked

Viewed 92 times

1

I’m building a regular expression to validate plane registrations. They are always in this sequential format:

  • 2 capital letters A to Z
  • Hyphen
  • 3 numbers

Totaling 6 characters.

I did the following structure, but I can’t validate it:

^[A-Z]{2}-[0-9]{3}$

The test string is:

AB-123

How can I validate this string in this format? Remembering that:

  • AB123 is invalid
  • A1234 is invalid
  • A-1234 is invalid
  • AB-1234 is invalid

--- EDIT It was just a flaw in the validator, when doing the test again, gave match on the correct string.

  • 4

    Seems correct, as is html/js?

  • 3

    Confirming that it works: https://regex101.com/r/cv7G4V/1

  • Strange, in the same validator (regex101) that was testing, did not give match in any circumstances... Now, when opening the validator again, it worked correctly.

  • The validator presented as an error, but it was only an instability. The REGEX presented works.

  • ^[A-Z]{2}- d{3}$

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.