GH avatar Bite 215. Validate a license key

Complete the validate_license function writing a regular expression that matches a PyBites license key which:

  • Starts with PB,
  • following 4 times dash (-) and 8 chars which can be upper case chars or digits,
  • for example: PB-U8N435EH-PG65PW87-IXPWQG5T-898XSZI4 would be a valid license key.

Return a bool (we added some type hinting for convenience).

Example how this function would work:

>>> import re
>>> from license import validate_license
>>> validate_license('PB-U8N435EH-PG65PW87-IXPWQG5T-898XSZI4')
True
>>> validate_license('pb-U8N435EH-PG65PW87-IXPWQG5T-898XSZI4')
False
>>> validate_license('bogus')
False
>>> validate_license('PB-U8N435EH-PG65PW87-IXPWQG5T-898XSZ..')
False

Have fun and code more Python!

go back Beginner level
Bitecoin 2X

109 out of 111 users completed this Bite.
Will you be Pythonista #110 to crack this Bite?
Resolution time: ~27 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.5 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Buy Now Login and get coding
We use Python 3.7