#K12026. Valid Hexadecimal Color Code Checker
Valid Hexadecimal Color Code Checker
Valid Hexadecimal Color Code Checker
You are given a string as input. Your task is to determine whether it is a valid hexadecimal color code.
A valid hexadecimal color code must satisfy the following conditions:
- It starts with the character
#
. - It is followed by exactly six characters.
- Each of these six characters must be a digit (
0
-9
) or a letter fromA
toF
(case insensitive).
For example, #1A2B3C
is valid, but #123abG
is not (because G
is not a valid hexadecimal digit). Similarly, the code must contain exactly six hexadecimal digits after the #
.
Your solution should read from standard input and produce the result to standard output.
inputFormat
The input consists of a single line containing a string s, which represents the candidate hexadecimal color code.
Note: The string may include leading or trailing whitespace which should be ignored.
outputFormat
Output a single line with True
if the input string is a valid hexadecimal color code, or False
otherwise.
#1A2B3C
True