Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Regular Expressions/Hexadecimal color/readme.md
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions Regular Expressions/Hexadecimal color/validateHexColor.js
Original file line number Diff line number Diff line change
@@ -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";

if (hexColorRegex.test(colorCode)) {
gs.info("Valid hexadecimal color");
}
else {
gs.info("Invalid hexadecimal color");
}
Loading