Skip to content

Instantly share code, notes, and snippets.

@topdown
Created March 16, 2013 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topdown/5178652 to your computer and use it in GitHub Desktop.
Save topdown/5178652 to your computer and use it in GitHub Desktop.
Regex validate hex color. Validates the hex color value skipping over non-valid values.
\b(?<=#)(([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}))\b
#333333 = valid
#abcde0 = valid
#333 = valid
#4 = not valid
#44 = not valid
#4444 = not valid
#44444 = not valid
#4444444 = not valid
#33333g = not valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment