Check if a value is a valid hexadecimal color code
Code snippet to test if a string value is in the proper hexadecimal color format.
const isHexColor = (hex) => {const regex = /^#?([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$/;return regex.test(hex);}
How to use
This function returns true
or false
depending if the value passed in follows the hexadecimal color code syntax.