Verify hex color string

<?php

//Check for a hex color string '#c1c2b4'
if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
{
//Verified hex color
}

//Check for a hex color string without hash 'c1c2b4'
else if(preg_match('/^[a-f0-9]{6}$/i', $color)) //hex color is valid
{
$fix_color = '#' . $color;
}

?>

0 Comments

You must be logged in to post a comment.