if($colour &&
((strlen($colour) == 7 && preg_match("/#[0-9a-fA-F]{6}/",$colour)) ||
(strlen($colour) == 4 && preg_match("/#[0-9a-fA-F]{3}/",$colour)))) {
- If $colour has a value AND
- $colour is a 7 digit string and conforms to the 7 digit hex colour format OR
- $colour is a 4 digit string and conforms to the 4 digit hex colour format
(String lengths include hash
, hence 3 & 6 become 4 & 7)