View Single Post
Old 11-03-2007, 11:59 AM   #13 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Quite true, Jim! I totally overlooked that possibility.

PHP Code:
function is_colour($szHex)
{
    
/* Prepend the hash symbol */
    
if(substr($szHex01) != '#')
    {
        
$szHex '#' $szHex;
    }
    
    
    
/* If we can save a call to regex then why not! */
    
    
$iCharacters strlen($szHex);

    if(
$iCharacters != && $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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote