Determine whether it is color

 

 The regularity of judging the color:

 

  

const hexColors = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/
const rgbColors = /^[rR][gG][Bb][Aa]?[\(]([\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?),){2}[\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?),?[\s]*(0\.\d{1,2}|1|0)?[\)]{1}$/g
export function isColors (value) {
  return hexColors.test(value) || rgbColors.test(value)
}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326893447&siteId=291194637