Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
JavaScript - Regular Expression to Validate Hexidecimal Color

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!