#C12893. Color Code Validator
Color Code Validator
Color Code Validator
Write a program to validate a hexadecimal color code. A valid color code must satisfy all of the following conditions:
(\bullet) It is exactly 7 characters long.
(\bullet) It starts with the symbol #
.
(\bullet) The remaining 6 characters must be valid hexadecimal digits, i.e. they must belong to the set ({0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F}).
If the input meets these criteria, output the color code in uppercase. Otherwise, output a specific error message as follows:
- If the length is not 7, output: "Color code must be 7 characters long."
- If the code does not start with
#
, output: "Color code must start with '#'." - If any of the remaining characters is not a valid hexadecimal digit, output: "The remaining characters must be valid hexadecimal digits."
inputFormat
The input consists of a single line containing a string which is the color code to be validated.
outputFormat
Output the validated color code in uppercase if it is valid. If the color code is invalid, output the specific error message according to the rule violated.## sample
#1a2B3c
#1A2B3C