function GoodColor(color)
{
var color2="";
var result=true;
var e=document.getElementById('mydiv');
e.style.borderColor="";
e.style.borderColor=color;
color2=e.style.borderColor;
if (color2.length==0){result=false;}
e.style.borderColor="";
return result;
}
/* getRGBA:
Get the RGBA values of a color.
If input is not a color, returns NULL, else returns an array of 4 values:
red (0-255), green (0-255), blue (0-255), alpha (0-1)
*/
function getRGBA(value) {
// get/create a 0 pixel element at the end of the document, to use to test properties against the client browser
var e = document.getElementById('test_style_element');
if (e == null) {
e = document.createElement('span');
e.id = 'test_style_element';
e.style.width = 0;
e.style.height = 0;
e.style.borderWidth = 0;
document.body.appendChild(e);
}
// use the browser to get the computed value of the input
e.style.borderColor = '';
e.style.borderColor = value;
if (e.style.borderColor == '') return null;
var computedStyle = window.getComputedStyle(e);
var c
if (typeof computedStyle.borderBottomColor != 'undefined') {
// as always, MSIE has to make life difficult
c = window.getComputedStyle(e).borderBottomColor;
} else {
c = window.getComputedStyle(e).borderColor;
}
var numbersAndCommas = c.replace(new RegExp('[^0-9.,]+','g'),'');
var values = numbersAndCommas.split(',');
for (var i = 0; i < values.length; i++)
values[i] = Number(values[i]);
if (values.length == 3) values.push(1);
return values;
}
////////////////////////////////////////////////////////////////////////////////
// isHex(). Is this a hex string/value?
// Arguments : 0 = Item to test
// 1 = V(alue) or S(tring). Default is STRING.
////////////////////////////////////////////////////////////////////////////////
function isHex()
{
var p = 0;
var re1 = /(\n|\r)+/g;
var re2 = /[\Wg-zG-Z]/;
var re3 = /v/i;
//
// Make sure the string is really a string.
//
var s = arguments[0];
if( typeof s != "string" ){ s = s.toString(); }
//
// Check if this is a hex VALUE
// and NOT a hex STRING.
//
var opt = arguments[1];
if( re3.test(opt) && (s.length % 2 > 0) ){ return "false"; }
//
// Remove any returns. BinHex files can be megabytes in length with 80
// column information. So we have to remove all returns first.
//
s.replace( re1, "" );
//
// IF they send us something with the universal "0x" or the HTML "#" on the
// front of it - we have to FIRST move where we look at the string.
//
if( s.substr(0,1) == "#" ){ p = 1; }
else if( s.substr(0,2).toLowerCase() == "0x" ){ p = 2; }
if( re2.test(s.substr(p,s.length)) ){ return "false"; }
return "true";
}
alert("HELLO There!");
alert(isHex("abcdef"));
alert(isHex("0x83464"));
alert(isHex("#273847"));
alert(isHex("This is a test"));
alert(isHex(0x5346));