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')
>>> validate_license('pb-U8N435EH-PG65PW87-IXPWQG5T-898XSZI4')
>>> validate_license('bogus')
>>> validate_license('PB-U8N435EH-PG65PW87-IXPWQG5T-898XSZ..')

Have fun and code more Python!

Login and get coding
go back Beginner level
Bitecoin 2X

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

We use Python 3.8