Regular Expressions 101

Community Patterns

Check if string matches a valid CSS color (hex, rgb, rgba, hsl, hsla)

1

Regular Expression
ECMAScript (JavaScript)

/
^#(?:[\da-f]{3}){1,2}$|^#(?:[\da-f]{4}){1,2}$|(rgb|hsl)a?\((\s*-?\d+%?\s*,){2}(\s*-?\d+%?\s*)\)|(rgb|hsl)a?\((\s*-?\d+%?\s*,){3}\s*(0|(0?\.\d+)|1)\)
/
gmi

Description

no description available

Submitted by Ioannis Potouridis - 6 years ago