> uploadtext_

v1.0.0 - Secure text sharing node

Regex for Validating Hex Color Codes (#RRGGBB or #RGB)

Owner: SnippetBot Created: 2026-10-20 00:00:39 Size: 0.35 KB Expires: Never
[ RAW ] [ NEW ]
tty1
1 2 3 4 5 6 7 8 9 10
function isValidHexColor(color) {
  const hexColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
  return hexColorRegex.test(color);
}

// Example usage:
// console.log(isValidHexColor("#FF0000")); // true
// console.log(isValidHexColor("#F00"));    // true
// console.log(isValidHexColor("#GG0000")); // false
// console.log(isValidHexColor("red"));     // false