Check if the input starts with #, rgb or rgba.
In rgb check if 2 commas and in rgba check if 3 commas
Check if integers check if within 255 check in rgba if last number is greater or less than 0 and 1
Unfortunately, that doesn't even come close to checking all valid CSS colours - there are many, many, named colours that are completely valid (red, white, green, burlywood, chartreuse, etc.) as well as CSS variables like var(--myColour).
Also, checking if it starts with # really is not enough in the case of hex values.
There's actually a very quick, short way of checking ALL of this... but I won't give it away here just yet
Check if the input starts with #, rgb or rgba.
In rgb check if 2 commas and in rgba check if 3 commas
Check if integers check if within 255 check in rgba if last number is greater or less than 0 and 1
Unfortunately, that doesn't even come close to checking all valid CSS colours - there are many, many, named colours that are completely valid (
red
,white
,green
,burlywood
,chartreuse
, etc.) as well as CSS variables likevar(--myColour)
.Also, checking if it starts with
#
really is not enough in the case of hex values.There's actually a very quick, short way of checking ALL of this... but I won't give it away here just yet
I thought it is a quick thing. I know it is not 100% correct method. But now I got your point.