Community Patterns

Community Library Entry

5

Regular Expression
Created·2015-12-02 11:14
Flavor·PCRE (Legacy)

/
^#?([0-9a-f]{6}|[0-9a-f]{3})$
/
i
Open regex in editor

Description

Validates hexadecimal color codes based on the following rule set:

  • Optionally starting with a hash.
  • 3 or 6 characters in length.
  • Using the [0-9a-f] character set.
Submitted by Nathaniel Blackburn