Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^#(([\da-fA-F]{3}){1,2}|([\da-fA-F]{4}){1,2})$
/

Description

CSS Hex Color Regex for JS

  • Supports alpha value (4 and 8 character hex codes) introduced in CSS Color Module Level 4
  • Well tested
Submitted by anonymous - 5 years ago