If I have a string that is a CSS code to be used as a color, Is it possible to check the value validity?
What i want is:
A function or a regex to validate if inputted code is a valid CSS code where it returns true when the value is a CSS function as linear-gradient
, color names as red
, hex, rgb, hsl colors or initial, inherit, currentColor, transparent
values, and returns false otherwise.
Like:
check('linear-gradient(140deg, rgba(0, 0, 0, 1) 0%, rgba(85, 85, 85, 1) 89%, rgba(153, 153, 153, 1) 100%)'); // should return true
check('#abcdzzff') // should return false
check('aquamarin') // should also return false (missing e)
Thanks.