SOURCE

const checkIsColor = (colorVal) => {
    let reg = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
    if (!reg.test(colorVal)) {
        reg = /^[rR][gG][Bb][Aa]?[\(]((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?),){2}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?),?(0\.\d{1,2}|1|0)?[\)]{1}$/;
        if (!reg.test(colorVal)) {
            return false;
        } else {
            return true;
        }
    } else {
        return true;
    }
}
const str = '#ffffff'
console.log(checkIsColor(str))
console 命令行工具 X clear

                    
>
console