Skip to content

Instantly share code, notes, and snippets.

@LunaCodeGirl
Created February 1, 2014 01:43
Show Gist options
  • Save LunaCodeGirl/8746738 to your computer and use it in GitHub Desktop.
Save LunaCodeGirl/8746738 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