We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44deb4e commit dd29cc2Copy full SHA for dd29cc2
Regular Expressions/Hexadecimal color/readme.md
@@ -0,0 +1,9 @@
1
+## This code snippet helps validating the hexadecimal color codes ##
2
+
3
+Based on the regular expression, the following formats are allowed:
4
+* #ABC
5
+* #AB1
6
+* #123
7
+* #ABCDEF
8
+* #ABC123
9
+* #123456
Regular Expressions/Hexadecimal color/validateHexColor.js
@@ -0,0 +1,15 @@
+/**
+* Hexadecimal 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";
10
+if (hexColorRegex.test(colorCode)) {
11
+ gs.info("Valid hexadecimal color");
12
+}
13
+else {
14
+ gs.info("Invalid hexadecimal color");
15
0 commit comments