Regex for Hex color code

Matches a #RGB or #RRGGBB hex color code.

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Proof it works

5/5 sample tests passed · compiles: true

SampleShould matchResult
#fff yes pass
#A1B2C3 yes pass
fff no pass
#12 no pass
#GGGGGG no pass

Try your own input

Related patterns