I am trying to create a regular expression in JavaScript to see if a string is a valid hexidecimal color. From my understanding, hexidecimal colors can be 3-6 characters long (if you ignore the leading '#'). Each character must be in the range of A-F, a-f, and 0-9. In an attempt to write this regular expression, I have the following:
let value = 'abcxyz';
let rex = new RegExp('[A-F0-9]{3,6}', 'i');
let result = rex.test(value);
console.log(`value: '${value}' is a hexidecimal color: ${result}`);
Oddly, this prints:
value: 'abcxyz' is a hexidecimal color: true
I do not see how value
can possibly match the regular expression provided. What am I doing wrong?