public static function validateHexColorString(string $hex) : bool
    {
        // optional leading hash #
        $length = strlen( ltrim($hex, '#') );

        // must be 3 or 6 characters
        switch ($length) {
            case 3: break;
            case 6: break;
            default: return false;
        }

        return preg_match('/^#?[0-9a-fA-F]{3,6}$/', $hex) === 1;
    }