Color validation

WJP Here's a procedure that validates color specifications, both names and hexadecimal RGB specs. IsColorSpecQ returns 1 if its argument is either a recognized X11 color name or a well formed hexadecimal RGB specification. If so desired, the two routines on which it is based, IsColorNameQ and IsColorNumericQ can also be exported.

 namespace eval validcolor {
    namespace export IsColorSpecQ;
    variable CN;

    set CN([list ghost white])  1;  set CN([list white smoke])  1;  set CN([list floral white])  1;
    set CN([list antique white])  1;  set CN([list old lace])  1;  set CN([list papaya whip]) 1
    set CN([list blanched almond])  1;  set CN([list peach puff])  1;  set CN([list navajo white]) 1
    set CN([list lemon chiffon])  1;  set CN([list mint cream])  1;  set CN([list alice blue]) 1
    set CN([list lavender blush])  1;  set CN([list misty rose])  1;  set CN([list dark slate gray]) 1
    set CN([list dark slate grey])  1;  set CN([list dim gray])  1;  set CN([list dim grey]) 1
    set CN([list slate gray])  1;  set CN([list slate grey])  1;  set CN([list light slate gray]) 1
    set CN([list light slate grey])  1;  set CN([list light grey])  1;  set CN([list light gray]) 1
    set CN([list midnight blue])  1;  set CN([list navy blue])  1;  set CN([list cornflower blue]) 1
    set CN([list dark slate blue])  1;  set CN([list slate blue])  1;  set CN([list medium slate blue]) 1
    set CN([list light slate blue])  1;  set CN([list medium blue])  1;  set CN([list royal blue]) 1
    set CN([list dodger blue])  1;  set CN([list deep sky blue])  1;  set CN([list sky blue]) 1
    set CN([list light sky blue])  1;  set CN([list steel blue])  1;  set CN([list light steel blue]) 1
    set CN([list light blue])  1;  set CN([list powder blue])  1;  set CN([list pale turquoise]) 1
    set CN([list dark turquoise])  1;  set CN([list medium turquoise])  1;  set CN([list light cyan]) 1
    set CN([list cadet blue])  1;  set CN([list medium aquamarine])  1;  set CN([list dark green]) 1
    set CN([list dark olive green])  1;  set CN([list dark sea green])  1;  set CN([list sea green]) 1
    set CN([list medium sea green])  1;  set CN([list light sea green])  1;  set CN([list pale green]) 1
    set CN([list spring green])  1;  set CN([list lawn green])  1;  set CN([list medium spring green]) 1
    set CN([list green yellow])  1;  set CN([list lime green])  1;  set CN([list yellow green]) 1
    set CN([list forest green])  1;  set CN([list olive drab])  1;  set CN([list dark khaki]) 1
    set CN([list pale goldenrod])  1;  set CN([list light goldenrod yellow])  1;  set CN([list light yellow]) 1
    set CN([list light goldenrod])  1;  set CN([list dark goldenrod])  1;  set CN([list rosy brown]) 1
    set CN([list indian red])  1;  set CN([list saddle brown])  1;  set CN([list sandy brown]) 1
    set CN([list dark salmon])  1;  set CN([list light salmon])  1;  set CN([list dark orange]) 1
    set CN([list light coral])  1;  set CN([list orange red])  1;  set CN([list hot pink]) 1
    set CN([list deep pink])  1;  set CN([list light pink])  1;  set CN([list pale violet red]) 1
    set CN([list medium violet red])  1;  set CN([list violet red])  1;  set CN([list medium orchid]) 1
    set CN([list dark orchid])  1;  set CN([list dark violet])  1;  set CN([list blue violet]) 1
    set CN([list medium purple])  1;  set CN(snow)  1;  set CN(GhostWhite) 1
    set CN(WhiteSmoke)  1;  set CN(gainsboro)  1;  set CN(FloralWhite) 1
    set CN(OldLace)  1;  set CN(linen)  1;  set CN(AntiqueWhite) 1
    set CN(PapayaWhip)  1;  set CN(BlanchedAlmond)  1;  set CN(bisque) 1
    set CN(PeachPuff)  1;  set CN(NavajoWhite)  1;  set CN(moccasin) 1
    set CN(cornsilk)  1;  set CN(ivory)  1;  set CN(LemonChiffon) 1
    set CN(seashell)  1;  set CN(honeydew)  1;  set CN(MintCream) 1
    set CN(azure)  1;  set CN(AliceBlue)  1;  set CN(lavender) 1
    set CN(LavenderBlush)  1;  set CN(MistyRose)  1;  set CN(white) 1
    set CN(black)  1;  set CN(DarkSlateGray)  1;  set CN(DarkSlateGrey) 1
    set CN(DimGray)  1;  set CN(DimGrey)  1;  set CN(SlateGray) 1
    set CN(SlateGrey)  1;  set CN(LightSlateGray)  1;  set CN(LightSlateGrey) 1
    set CN(gray)  1;  set CN(grey)  1;  set CN(LightGrey) 1
    set CN(LightGray)  1;  set CN(MidnightBlue)  1;  set CN(navy) 1
    set CN(NavyBlue)  1;  set CN(CornflowerBlue)  1;  set CN(DarkSlateBlue) 1
    set CN(SlateBlue)  1;  set CN(MediumSlateBlue)  1;  set CN(LightSlateBlue) 1
    set CN(MediumBlue)  1;  set CN(RoyalBlue)  1;  set CN(blue) 1
    set CN(DodgerBlue)  1;  set CN(DeepSkyBlue)  1;  set CN(SkyBlue) 1
    set CN(LightSkyBlue)  1;  set CN(SteelBlue)  1;  set CN(LightSteelBlue) 1
    set CN(LightBlue)  1;  set CN(PowderBlue)  1;  set CN(PaleTurquoise) 1
    set CN(DarkTurquoise)  1;  set CN(MediumTurquoise)  1;  set CN(turquoise) 1
    set CN(cyan)  1;  set CN(LightCyan)  1;  set CN(CadetBlue)  1;  set CN(MediumAquamarine) 1
    set CN(aquamarine)  1;  set CN(DarkGreen)  1;  set CN(DarkOliveGreen) 1
    set CN(DarkSeaGreen)  1;  set CN(SeaGreen)  1;  set CN(MediumSeaGreen) 1
    set CN(LightSeaGreen)  1;  set CN(PaleGreen)  1;  set CN(SpringGreen)  1;
    set CN(LawnGreen)  1;  set CN(green)  1;  set CN(chartreuse) 1
    set CN(MediumSpringGreen)  1;  set CN(GreenYellow)  1;  set CN(LimeGreen) 1
    set CN(YellowGreen)  1;  set CN(ForestGreen)  1;  set CN(OliveDrab) 1
    set CN(DarkKhaki)  1;  set CN(khaki)  1;  set CN(PaleGoldenrod) 1
    set CN(LightGoldenrodYellow)  1;  set CN(LightYellow)  1;  set CN(yellow) 1
    set CN(gold)  1;  set CN(LightGoldenrod)  1;  set CN(goldenrod) 1
    set CN(DarkGoldenrod)  1;  set CN(RosyBrown)  1;  set CN(IndianRed) 1
    set CN(SaddleBrown)  1;  set CN(sienna)  1;  set CN(peru) 1
    set CN(burlywood)  1;  set CN(beige)  1;  set CN(wheat) 1
    set CN(SandyBrown)  1;  set CN(tan)  1;  set CN(chocolate) 1
    set CN(firebrick)  1;  set CN(brown)  1;  set CN(DarkSalmon) 1
    set CN(salmon)  1;  set CN(LightSalmon)  1;  set CN(orange) 1
    set CN(DarkOrange)  1;  set CN(coral)  1;  set CN(LightCoral) 1
    set CN(tomato)  1;  set CN(OrangeRed)  1;  set CN(red) 1
    set CN(HotPink)  1;  set CN(DeepPink)  1;  set CN(pink) 1
    set CN(LightPink)  1;  set CN(PaleVioletRed)  1;  set CN(maroon) 1
    set CN(MediumVioletRed)  1;  set CN(VioletRed)  1;  set CN(magenta) 1
    set CN(violet)  1;  set CN(plum)  1;  set CN(orchid) 1
    set CN(MediumOrchid)  1;  set CN(DarkOrchid)  1;  set CN(DarkViolet) 1
    set CN(BlueViolet)  1;  set CN(purple)  1;  set CN(MediumPurple) 1
    set CN(thistle)  1;  set CN(snow1)  1;  set CN(snow2) 1
    set CN(snow3)  1;  set CN(snow4)  1;  set CN(seashell1) 1
    set CN(seashell2)  1;  set CN(seashell3)  1;  set CN(seashell4) 1
    set CN(AntiqueWhite1)  1;  set CN(AntiqueWhite2)  1;  set CN(AntiqueWhite3) 1
    set CN(AntiqueWhite4)  1;  set CN(bisque1)  1;  set CN(bisque2) 1
    set CN(bisque3)  1;  set CN(bisque4)  1;  set CN(PeachPuff1) 1
    set CN(PeachPuff2)  1;  set CN(PeachPuff3)  1;  set CN(PeachPuff4) 1
    set CN(NavajoWhite1)  1;  set CN(NavajoWhite2)  1;  set CN(NavajoWhite3) 1
    set CN(NavajoWhite4)  1;  set CN(LemonChiffon1)  1;  set CN(LemonChiffon2) 1
    set CN(LemonChiffon3)  1;  set CN(LemonChiffon4)  1;  set CN(cornsilk1) 1
    set CN(cornsilk2)  1;  set CN(cornsilk3)  1;  set CN(cornsilk4) 1
    set CN(ivory1)  1;  set CN(ivory2)  1;  set CN(ivory3) 1
    set CN(ivory4)  1;  set CN(honeydew1)  1;  set CN(honeydew2) 1
    set CN(honeydew3)  1;  set CN(honeydew4)  1;  set CN(LavenderBlush1) 1
    set CN(LavenderBlush2)  1;  set CN(LavenderBlush3)  1;  set CN(LavenderBlush4) 1
    set CN(MistyRose1)  1;  set CN(MistyRose2)  1;  set CN(MistyRose3) 1
    set CN(MistyRose4)  1;  set CN(azure1)  1;  set CN(azure2) 1
    set CN(azure3)  1;  set CN(azure4)  1;  set CN(SlateBlue1) 1
    set CN(SlateBlue2)  1;  set CN(SlateBlue3)  1;  set CN(SlateBlue4) 1
    set CN(RoyalBlue1)  1;  set CN(RoyalBlue2)  1;  set CN(RoyalBlue3) 1
    set CN(RoyalBlue4)  1;  set CN(blue1)  1;  set CN(blue2) 1
    set CN(blue3)  1;  set CN(blue4)  1;  set CN(DodgerBlue1) 1
    set CN(DodgerBlue2)  1;  set CN(DodgerBlue3)  1;  set CN(DodgerBlue4) 1
    set CN(SteelBlue1)  1;  set CN(SteelBlue2)  1;  set CN(SteelBlue3) 1
    set CN(SteelBlue4)  1;  set CN(DeepSkyBlue1)  1;  set CN(DeepSkyBlue2) 1
    set CN(DeepSkyBlue3)  1;  set CN(DeepSkyBlue4)  1;  set CN(SkyBlue1) 1
    set CN(SkyBlue2)  1;  set CN(SkyBlue3)  1;  set CN(SkyBlue4) 1
    set CN(LightSkyBlue1)  1;  set CN(LightSkyBlue2)  1;  set CN(LightSkyBlue3) 1
    set CN(LightSkyBlue4)  1;  set CN(SlateGray1)  1;  set CN(SlateGray2) 1
    set CN(SlateGray3)  1;  set CN(SlateGray4)  1;  set CN(LightSteelBlue1) 1
    set CN(LightSteelBlue2)  1;  set CN(LightSteelBlue3)  1;  set CN(LightSteelBlue4) 1
    set CN(LightBlue1)  1;  set CN(LightBlue2)  1;  set CN(LightBlue3) 1
    set CN(LightBlue4)  1;  set CN(LightCyan1)  1;  set CN(LightCyan2) 1
    set CN(LightCyan3)  1;  set CN(LightCyan4)  1;  set CN(PaleTurquoise1) 1
    set CN(PaleTurquoise2)  1;  set CN(PaleTurquoise3)  1;  set CN(PaleTurquoise4) 1
    set CN(CadetBlue1)  1;  set CN(CadetBlue2)  1;  set CN(CadetBlue3) 1
    set CN(CadetBlue4)  1;  set CN(turquoise1)  1;  set CN(turquoise2) 1
    set CN(turquoise3) 1; set CN(turquoise4)  1;  set CN(cyan1) 1
    set CN(cyan2)  1;  set CN(cyan3)  1;  set CN(cyan4) 1
    set CN(DarkSlateGray1)  1;  set CN(DarkSlateGray2)  1;  set CN(DarkSlateGray3) 1
    set CN(DarkSlateGray4)  1;  set CN(aquamarine1)  1;  set CN(aquamarine2) 1
    set CN(aquamarine3)  1;  set CN(aquamarine4)  1;  set CN(DarkSeaGreen1) 1
    set CN(DarkSeaGreen2)  1;  set CN(DarkSeaGreen3)  1;  set CN(DarkSeaGreen4) 1
    set CN(SeaGreen1)  1;  set CN(SeaGreen2)  1;  set CN(SeaGreen3) 1
    set CN(SeaGreen4)  1;  set CN(PaleGreen1)  1;  set CN(PaleGreen2) 1
    set CN(PaleGreen3)  1;  set CN(PaleGreen4)  1;  set CN(SpringGreen1) 1
    set CN(SpringGreen2)  1;  set CN(SpringGreen3)  1;  set CN(SpringGreen4) 1
    set CN(green1)  1;  set CN(green2)  1;  set CN(green3) 1
    set CN(green4)  1;  set CN(chartreuse1)  1;  set CN(chartreuse2) 1
    set CN(chartreuse3)  1;  set CN(chartreuse4)  1;  set CN(OliveDrab1) 1
    set CN(OliveDrab2)  1;  set CN(OliveDrab3)  1;  set CN(OliveDrab4) 1
    set CN(DarkOliveGreen1)  1;  set CN(DarkOliveGreen2)  1;  set CN(DarkOliveGreen3) 1
    set CN(DarkOliveGreen4)  1;  set CN(khaki1)  1;  set CN(khaki2) 1
    set CN(khaki3)  1;  set CN(khaki4)  1;  set CN(LightGoldenrod1) 1
    set CN(LightGoldenrod2)  1;  set CN(LightGoldenrod3)  1;  set CN(LightGoldenrod4) 1
    set CN(LightYellow1)  1;  set CN(LightYellow2)  1;  set CN(LightYellow3) 1
    set CN(LightYellow4)  1;  set CN(yellow1)  1;  set CN(yellow2) 1
    set CN(yellow3)  1;  set CN(yellow4)  1;  set CN(gold1) 1
    set CN(gold2)  1;  set CN(gold3)  1;  set CN(gold4) 1
    set CN(goldenrod1)  1;  set CN(goldenrod2)  1;  set CN(goldenrod3) 1
    set CN(goldenrod4)  1;  set CN(DarkGoldenrod1)  1;  set CN(DarkGoldenrod2) 1
    set CN(DarkGoldenrod3)  1;  set CN(DarkGoldenrod4)  1;  set CN(RosyBrown1) 1
    set CN(RosyBrown2)  1;  set CN(RosyBrown3)  1;  set CN(RosyBrown4) 1
    set CN(IndianRed1)  1;  set CN(IndianRed2)  1;  set CN(IndianRed3) 1
    set CN(IndianRed4)  1;  set CN(sienna1)  1;  set CN(sienna2) 1
    set CN(sienna3)  1;  set CN(sienna4)  1;  set CN(burlywood1) 1
    set CN(burlywood2)  1;  set CN(burlywood3)  1;  set CN(burlywood4) 1
    set CN(wheat1)  1;  set CN(wheat2)  1;  set CN(wheat3) 1
    set CN(wheat4)  1;  set CN(tan1)  1;  set CN(tan2) 1
    set CN(tan3)  1;  set CN(tan4)  1;  set CN(chocolate1) 1
    set CN(chocolate2)  1;  set CN(chocolate3)  1;  set CN(chocolate4) 1
    set CN(firebrick1)  1;  set CN(firebrick2)  1;  set CN(firebrick3) 1
    set CN(firebrick4)  1;  set CN(brown1)  1;  set CN(brown2) 1
    set CN(brown3)  1;  set CN(brown4)  1;  set CN(salmon1) 1
    set CN(salmon2)  1;  set CN(salmon3)  1;  set CN(salmon4) 1
    set CN(LightSalmon1)  1;  set CN(LightSalmon2)  1;  set CN(LightSalmon3) 1
    set CN(LightSalmon4)  1;  set CN(orange1)  1;  set CN(orange2) 1
    set CN(orange3)  1;  set CN(orange4)  1;  set CN(DarkOrange1) 1
    set CN(DarkOrange2)  1;  set CN(DarkOrange3)  1;  set CN(DarkOrange4) 1
    set CN(coral1)  1;  set CN(coral2)  1;  set CN(coral3) 1
    set CN(coral4)  1;  set CN(tomato1)  1;  set CN(tomato2) 1
    set CN(tomato3)  1;  set CN(tomato4)  1;  set CN(OrangeRed1) 1
    set CN(OrangeRed2)  1;  set CN(OrangeRed3)  1;  set CN(OrangeRed4) 1
    set CN(red1)  1;  set CN(red2)  1;  set CN(red3) 1
    set CN(red4)  1;  set CN(DeepPink1)  1;  set CN(DeepPink2) 1
    set CN(DeepPink3)  1;  set CN(DeepPink4)  1;  set CN(HotPink1) 1
    set CN(HotPink2)  1;  set CN(HotPink3)  1;  set CN(HotPink4) 1
    set CN(pink1)  1;  set CN(pink2)  1;  set CN(pink3) 1
    set CN(pink4)  1;  set CN(LightPink1)  1;  set CN(LightPink2) 1
    set CN(LightPink3)  1;  set CN(LightPink4)  1;  set CN(PaleVioletRed1) 1
    set CN(PaleVioletRed2)  1;  set CN(PaleVioletRed3)  1;  set CN(PaleVioletRed4) 1
    set CN(maroon1)  1;  set CN(maroon2)  1;  set CN(maroon3) 1
    set CN(maroon4)  1;  set CN(VioletRed1)  1;  set CN(VioletRed2) 1
    set CN(VioletRed3)  1;  set CN(VioletRed4)  1;  set CN(magenta1) 1
    set CN(magenta2)  1;  set CN(magenta3)  1;  set CN(magenta4) 1
    set CN(orchid1)  1;  set CN(orchid2)  1;  set CN(orchid3) 1
    set CN(orchid4)  1;  set CN(plum1)  1;  set CN(plum2) 1
    set CN(plum3)  1;  set CN(plum4)  1;  set CN(MediumOrchid1) 1
    set CN(MediumOrchid2)  1;  set CN(MediumOrchid3)  1;  set CN(MediumOrchid4) 1
    set CN(DarkOrchid1)  1;  set CN(DarkOrchid2)  1;  set CN(DarkOrchid3) 1
    set CN(DarkOrchid4)  1;  set CN(purple1)  1;  set CN(purple2) 1
    set CN(purple3)  1;  set CN(purple4)  1;  set CN(MediumPurple1) 1
    set CN(MediumPurple2)  1;  set CN(MediumPurple3)  1;  set CN(MediumPurple4) 1
    set CN(thistle1)  1;  set CN(thistle2)  1;  set CN(thistle3) 1
    set CN(thistle4)    1;      set CN(gray0)   1;      set CN(grey0) 1
    set CN(gray1)       1;      set CN(grey1)   1;      set CN(gray2) 1
    set CN(grey2)       1;      set CN(gray3)   1;      set CN(grey3) 1
    set CN(gray4)       1;      set CN(grey4)   1;      set CN(gray5) 1
    set CN(grey5)       1;      set CN(gray6)   1;      set CN(grey6) 1
    set CN(gray7)       1;      set CN(grey7)   1;      set CN(gray8) 1
    set CN(grey8)       1;      set CN(gray9)   1;      set CN(grey9) 1
    set CN(gray10)      1;      set CN(grey10)  1;      set CN(gray11) 1
    set CN(grey11)      1;      set CN(gray12)  1;      set CN(grey12) 1
    set CN(gray13)      1;      set CN(grey13)  1;      set CN(gray14) 1
    set CN(grey14)      1;      set CN(gray15)  1;      set CN(grey15) 1
    set CN(gray16)      1;      set CN(grey16)  1;      set CN(gray17) 1
    set CN(grey17)      1;      set CN(gray18)  1;      set CN(grey18) 1
    set CN(gray19)      1;      set CN(grey19)  1;      set CN(gray20) 1
    set CN(grey20)      1;      set CN(gray21)  1;      set CN(grey21) 1
    set CN(gray22)      1;      set CN(grey22)  1;      set CN(gray23) 1
    set CN(grey23)      1;      set CN(gray24)  1;      set CN(grey24) 1
    set CN(gray25)      1;      set CN(grey25)  1;      set CN(gray26) 1
    set CN(grey26)      1;      set CN(gray27)  1;      set CN(grey27) 1
    set CN(gray28)      1;      set CN(grey28)  1;      set CN(gray29) 1
    set CN(grey29)      1;      set CN(gray30)  1;      set CN(grey30) 1
    set CN(gray31)      1;      set CN(grey31)  1;      set CN(gray32) 1
    set CN(grey32)      1;      set CN(gray33)  1;      set CN(grey33) 1
    set CN(gray34)      1;      set CN(grey34)  1;      set CN(gray35) 1
    set CN(grey35)      1;      set CN(gray36)  1;      set CN(grey36) 1
    set CN(gray37)      1;      set CN(grey37)  1;      set CN(gray38) 1
    set CN(grey38)      1;      set CN(gray39)  1;      set CN(grey39) 1
    set CN(gray40)      1;      set CN(grey40)  1;      set CN(gray41) 1
    set CN(grey41)      1;      set CN(gray42)  1;      set CN(grey42) 1
    set CN(gray43)      1;      set CN(grey43)  1;      set CN(gray44) 1
    set CN(grey44)      1;      set CN(gray45)  1;      set CN(grey45) 1
    set CN(gray46)      1;      set CN(grey46)  1;      set CN(gray47) 1
    set CN(grey47)      1;      set CN(gray48)  1;      set CN(grey48) 1
    set CN(gray49)      1;      set CN(grey49)  1;      set CN(gray50) 1
    set CN(grey50)      1;      set CN(gray51)  1;      set CN(grey51) 1
    set CN(gray52)      1;      set CN(grey52)  1;      set CN(gray53) 1
    set CN(grey53)      1;      set CN(gray54)  1;      set CN(grey54) 1
    set CN(gray55)      1;      set CN(grey55)  1;      set CN(gray56) 1
    set CN(grey56)      1;      set CN(gray57)  1;      set CN(grey57) 1
    set CN(gray58)      1;      set CN(grey58)  1;      set CN(gray59) 1
    set CN(grey59)      1;      set CN(gray60)  1;      set CN(grey60) 1
    set CN(gray61)      1;      set CN(grey61)  1;      set CN(gray62) 1
    set CN(grey62)      1;      set CN(gray63)  1;      set CN(grey63) 1
    set CN(gray64)      1;      set CN(grey64)  1;      set CN(gray65) 1
    set CN(grey65)      1;      set CN(gray66)  1;      set CN(grey66) 1
    set CN(gray67)      1;      set CN(grey67)  1;      set CN(gray68) 1
    set CN(grey68)      1;      set CN(gray69)  1;      set CN(grey69) 1
    set CN(gray70)      1;      set CN(grey70)  1;      set CN(gray71) 1
    set CN(grey71)      1;      set CN(gray72)  1;      set CN(grey72) 1
    set CN(gray73)      1;      set CN(grey73)  1;      set CN(gray74) 1
    set CN(grey74)      1;      set CN(gray75)  1;      set CN(grey75) 1
    set CN(gray76)      1;      set CN(grey76)  1;      set CN(gray77) 1
    set CN(grey77)      1;      set CN(gray78)  1;      set CN(grey78) 1
    set CN(gray79)      1;      set CN(grey79)  1;      set CN(gray80) 1
    set CN(grey80)      1;      set CN(gray81)  1;      set CN(grey81) 1
    set CN(gray82)      1;      set CN(grey82)  1;      set CN(gray83) 1
    set CN(grey83)      1;      set CN(gray84)  1;      set CN(grey84) 1
    set CN(gray85)      1;      set CN(grey85)  1;      set CN(gray86) 1
    set CN(grey86)      1;      set CN(gray87)  1;      set CN(grey87) 1
    set CN(gray88)      1;      set CN(grey88)  1;      set CN(gray89) 1
    set CN(grey89)      1;      set CN(gray90)  1;      set CN(grey90) 1
    set CN(gray91)      1;      set CN(grey91)  1;      set CN(gray92) 1
    set CN(grey92)      1;      set CN(gray93)  1;      set CN(grey93) 1
    set CN(gray94)      1;      set CN(grey94)  1;      set CN(gray95) 1
    set CN(grey95)      1;      set CN(gray96)  1;      set CN(grey96) 1
    set CN(gray97)      1;      set CN(grey97)  1;      set CN(gray98) 1
    set CN(grey98)      1;      set CN(gray99)  1;      set CN(grey99) 1
    set CN(gray100)     1;      set CN(grey100) 1;

    proc IsColorNameQ {s} {
        variable CN
        if {[info exists CN($s)]} {
            return 1;
        } else {
            return 0;
        }
    }

  #RGB color specs can provide 8, 16, 24, or 32 bits for each of the three colors.
    proc IsColorNumericQ {s} {
        return [regexp \
                    {^\#([[:xdigit:]]{6}|[[:xdigit:]]{3}|[[:xdigit:]]{9}|[[:xdigit:]]{12})$} $s]
    }

    proc IsColorSpecQ {s} {
        if {[IsColorNameQ $s]} {
            return 1;
        } elseif {[IsColorNumericQ $s]} {
            return 1;
        } else {
            return 0;
        }
    }
    package provide validcolor
 }
 #end of namespace validcolor

Demo:

 puts "validcolor::IscolorSpecQ red = [validcolor::IsColorSpecQ red]"
 puts "validcolor::IscolorSpecQ reed = [validcolor::IsColorSpecQ reed]"
 puts "validcolor::IscolorSpecQ {sky blue} = [validcolor::IsColorSpecQ {sky blue}]"
 puts "validcolor::IscolorSpecQ \#FF0000 = [validcolor::IsColorSpecQ \#FF0000]"
 puts "validcolor::IscolorSpecQ \#FF000 = [validcolor::IsColorSpecQ \#FF000]"
 puts "validcolor::IscolorSpecQ \#FFF000000 = [validcolor::IsColorSpecQ \#FFF000000]"
 puts "validcolor::IscolorSpecQ \#FG0000 = [validcolor::IsColorSpecQ \#FG0000]"

MG An easier way of doing this, to check for a valid Tk colourname (I'm not sure if that's the same as a valid X11 colourname or not) is to use:

  proc validcolor2 {col {win .}} {
    return [expr {![catch {winfo rgb $win $col}]}]
  }

  validcolor2 {sky blue}