def validate_hex_color_string(hex_string):
    """Return True if received a valid hex color string.

    Parameters
    ==========
    hex_string (string)
        string in '#XXXXXX' or '#XXXXXXXX' format, where
        each pair of characters (except the leading '#')
        is the hexadecimal representation of an integer
        from 0 to 255 (all inclusive) further representing
        the value of a channel of a RGB(A) color.
    """
    ### string can't be empty
    if not hex_string:
        return False

    ### first character must be '#'
    if hex_string[0] != "#":
        return False

    ### remove '#' before continuing
    hex_string = hex_string[1:]

    ### remaining characters must count 6 or 8 (that is,
    ### there must be 2 characters for each channel,
    ### red, green, blue and, in some cases, alpha too)
    if not len(hex_string) in (6, 8):
        return False

    ### before continuing, make string all lowercase
    hex_string = hex_string.lower()

    ### characters must all be characters used in
    ### hexadecimal representations

    if any(char not in hexdigits for char in hex_string):
        return False

    ### if every test above passed (none of them returned),
    ### it means the string is valid, so return True
    return True
Return True if received a valid hex color string.

    Parameters
    ==========
    hex_string (string)
        string in '#XXXXXX' or '#XXXXXXXX' format, where
        each pair of characters (except the leading '#')
        is the hexadecimal representation of an integer
        from 0 to 255 (all inclusive) further representing
        the value of a channel of a RGB(A) color.
    
nodezator/ourstdlibs/color/utils.py