Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, February 3, 2016 5:03 PM
Hello,
I need to write regex to validate Windows product key.
Please help me on this.
thanks in advance.
Mahadevan.G
All replies (2)
Wednesday, February 3, 2016 5:18 PM âś…Answered
If it is 25-character code without special restrictions, then try this expression:
^([A-Z0-9]{5}-){4}[A-Z0-9]{5}$
Wednesday, February 3, 2016 5:18 PM
Do you only want to validate the 5 times 5 digits with 4 dashes product keys or do you want to validate the validity of the product key against Microsoft's generated keys? For the last you can't. For the first, then you need a regex which validates 1-9 or A-Z, 5 times, with 4 dashes between the blocks of 5 chars:
^[A-Z1-9]{5}(-[A-Z1-9]{5}){4}$
Dennis Bakker | Hobby developer | Microsoft Community Contributor
If you think this post is an answer to the question, please propose or mark this post as answer.
If you find this post helpful, please vote for this post.