Regular Expression To Match Microsoft Product Key

A regular expression to match a Microsoft Product Key, which is a 25-character code that’s used to activate Windows and helps verify that Windows hasn’t been used on more PCs than the Microsoft Software License Terms allow.

/^[A-Z1-9]{5}-[A-Z1-9]{5}-[A-Z1-9]{5}-[A-Z1-9]{5}-[A-Z1-9]{5}$/

Matches:

  • 12345-67891-12345-67891-12345
  • ABCDE-ABCDE-ABCDE-ABCDE-ABCDE

Non-matches:

  • 12345-67890-12345-67891-12345
  • ABCDE-ABCDEF-ABCDE-ABCDE-ABCDE