RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$
Description
Tests for valid HTML hexadecimal color codes. The # symbol is optional. And it will except either the 3 digit form for the 216 Web safe colors, or the full 6 digit form. I am use it on my site to allow users to customize the site's colors.
Matches
#00ccff | #039 | ffffcc
Non-Matches
blue | 0x000000 | #ff000
Author Rating: The rating for this expression. Chris Craft
Source http://www.cjcraft.com/
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: sfd
Name: sdf
Date: 6/15/2010 2:05:05 AM
Comment:
sdf


Title: pattern Title
Name: Carol
Date: 2/5/2010 11:53:19 AM
Comment:
This expression does not validate correctly. I was able to validate 3 alpha characters, which is not a valid color.


Title: Alternatives 2.1 [edit]
Name: TSMike
Date: 7/14/2006 4:34:24 AM
Comment:
Shorter than ^#?([0-9a-fA-F]{3}){1,2}$ shorter:^#?([0-9A-f]{3}){1,2}$


Title: Alternatives 2
Name: TSMike
Date: 7/14/2006 4:33:17 AM
Comment:
Shorter than ^#?([0-9a-fA-F]{3}){1,2}$ shorter:^#?([0-9A-F]{3}){1,2}$


Title: ? Issue w/old browsers
Name: Helper
Date: 9/8/2004 12:11:36 PM
Comment:
The ? character in this expression will not work on older browsers I have found.


Title: Alternatives
Name: SuperRembo
Date: 6/16/2004 1:00:50 PM
Comment:
Shorter (an more clear i think): ^#?[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$ Even shorter: ^#?([0-9a-fA-F]{3}){1,2}$


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials