^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ Matches: ✓ #FF5733 ✓ #abc ✓ FF5733 (without #)
^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
^#? makes the # optional, so both #FF5733 and FF5733 are valid.
Shorthand like #abc expands to #aabbcc. Both are valid CSS.