From 2eb61e46c03f9180e0f904dd17e987ff9bed708c Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 23 Mar 2020 21:19:46 +0530 Subject: [PATCH] fix: match possible whitespace chars at the start Signed-off-by: Chinmay D. Pai --- src/js/utils/colors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/utils/colors.js b/src/js/utils/colors.js index 8f4275c..e441bdd 100644 --- a/src/js/utils/colors.js +++ b/src/js/utils/colors.js @@ -37,8 +37,8 @@ export function lightenDarkenColor(color, amt) { export function isValidColor(string) { // https://stackoverflow.com/a/32685393 - let HEX_RE = /^(#)((?:[A-Fa-f0-9]{3}){1,2})$/i - let RGB_RE = /^(rgb|hsl)(a?)[(]\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*(?:,\s*([\d.]+)\s*)?[)]$/i + let HEX_RE = /(^\s*)(#)((?:[A-Fa-f0-9]{3}){1,2})$/i + let RGB_RE = /(^\s*)(rgb|hsl)(a?)[(]\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*(?:,\s*([\d.]+)\s*)?[)]$/i return HEX_RE.test(string) || RGB_RE.test(string); }