11-03-2007, 11:59 AM
|
#13 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Quite true, Jim! I totally overlooked that possibility.
PHP Code:
function is_colour($szHex) { /* Prepend the hash symbol */ if(substr($szHex, 0, 1) != '#') { $szHex = '#' . $szHex; } /* If we can save a call to regex then why not! */ $iCharacters = strlen($szHex);
if($iCharacters != 7 && $iCharacters != 4) { return false; } /* Check to see if the colour value is valid */ if(!preg_match('/^#{1}([0-9A-F]{6}|[0-9A-F]{3})$/i', $szHex)) { return false; } /* It's all good! */ return true; }
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|