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!

Login and get coding
go back Beginner level
Bitecoin 2X

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

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help