16进制颜色
验证 16进制颜色
。
语法
import { colorReg } from 'warbler-js';
const result = colorReg(value);
参数
value
(String) : 待验证字符串。
返回值
Boolean : 是否通过验证,true
通过验证, false
没有通过验证。
源码
const colorReg = (value) => {
const reg = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
return reg.test(value);
};
例子
import { colorReg } from 'warbler-js';
const result1 = colorReg('#fff')
const result2 = colorReg('#000000')
console.log(result1) // true
console.log(result2) // true