From 70e7919d40dfe91ffb9c2fb7b1254eefd37411a5 Mon Sep 17 00:00:00 2001 From: "Attila V." Date: Sat, 26 Oct 2024 14:14:27 +0200 Subject: [PATCH 1/3] Create validateHexColor.js --- .../Hexadecimal color/validateHexColor.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Regular Expressions/Hexadecimal color/validateHexColor.js diff --git a/Regular Expressions/Hexadecimal color/validateHexColor.js b/Regular Expressions/Hexadecimal color/validateHexColor.js new file mode 100644 index 0000000000..9fa1e45cef --- /dev/null +++ b/Regular Expressions/Hexadecimal color/validateHexColor.js @@ -0,0 +1,15 @@ +/** +* HHexadecimal color pattern. The following formats are allowed: +* #ABC | #AB1 | #123 +* #ABCDEF | #ABC123 | #123456 +*/ +const hexColorRegex = /^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/g; + +const colorCode = "#ABC123"; + +if (hexColorRegex.test(colorCode)) { + gs.info("Valid hexadecimal color"); +} +else { + gs.info("Invalid hexadecimal color"); +} From e3fcde9f31be80f0acff0421de41ba78efc00de5 Mon Sep 17 00:00:00 2001 From: "Attila V." Date: Sat, 26 Oct 2024 14:19:29 +0200 Subject: [PATCH 2/3] Create readme.md --- Regular Expressions/Hexadecimal color/readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Regular Expressions/Hexadecimal color/readme.md diff --git a/Regular Expressions/Hexadecimal color/readme.md b/Regular Expressions/Hexadecimal color/readme.md new file mode 100644 index 0000000000..44c9fe9aed --- /dev/null +++ b/Regular Expressions/Hexadecimal color/readme.md @@ -0,0 +1,9 @@ +## This code snippet helps validating the hexadecimal color codes ## + +Based on the regular expression, the following formats are allowed: +* #ABC +* #AB1 +* #123 +* #ABCDEF +* #ABC123 +* #123456 From 2971fcbf6ab019da5cba38a9bb86355085b32f49 Mon Sep 17 00:00:00 2001 From: "Attila V." Date: Sat, 26 Oct 2024 14:19:49 +0200 Subject: [PATCH 3/3] Update validateHexColor.js --- Regular Expressions/Hexadecimal color/validateHexColor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Regular Expressions/Hexadecimal color/validateHexColor.js b/Regular Expressions/Hexadecimal color/validateHexColor.js index 9fa1e45cef..6c2a26c512 100644 --- a/Regular Expressions/Hexadecimal color/validateHexColor.js +++ b/Regular Expressions/Hexadecimal color/validateHexColor.js @@ -1,5 +1,5 @@ /** -* HHexadecimal color pattern. The following formats are allowed: +* Hexadecimal color pattern. The following formats are allowed: * #ABC | #AB1 | #123 * #ABCDEF | #ABC123 | #123456 */