Scriptet
10-28-2009, 02:50 PM
Hi,
I need to use a preg match to check if a color entered is a valid hexidecminal color. I found the following off a website:
if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
{
}
This works great, but a hex color can also be 3 characters, and the preg match in question does not allow for this.
I have no idea how preg-matches work or how easy they are to code, but can this be amended to allow for 3 characters also?
I need to use a preg match to check if a color entered is a valid hexidecminal color. I found the following off a website:
if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
{
}
This works great, but a hex color can also be 3 characters, and the preg match in question does not allow for this.
I have no idea how preg-matches work or how easy they are to code, but can this be amended to allow for 3 characters also?