question 104 String Algorithms · easy
Is this a colour code?
A theme editor accepts colours as hex codes such as #1A2b3C: a # followed by exactly six hexadecimal digits (0–9 and a–f, in either case). Spaces at the ends are allowed. Check a typed colour before saving it.
Function
valid_colour(text)ReturnsTrue for
# plus six characters from 0123456789abcdefABCDEF (after stripping); otherwise FalseExamples
callvalid_colour('#1A2b3C')returnsTrue
callvalid_colour('#12345g')returnsFalse
callvalid_colour('#ffffff')returnsTrue