Skip to content

Instantly share code, notes, and snippets.

@kevinreynolds
Forked from LunaCodeGirl/HexadecimalColorRegex
Created August 14, 2017 07:28
Show Gist options
  • Save kevinreynolds/02277531c29b01f0599355858d4235e9 to your computer and use it in GitHub Desktop.
Save kevinreynolds/02277531c29b01f0599355858d4235e9 to your computer and use it in GitHub Desktop.
Regex for validating hexadecimal color codes.
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
^ #start of the line
# # must constains a "#" symbols
( # start of group #1
[A-Fa-f0-9]{6} # any strings in the list, with length of 6
| # ..or
[A-Fa-f0-9]{3} # any strings in the list, with length of 3
) # end of group #1
$ #end of the line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment