jsUtils.isHex()
Checks if the variable is a valid hexadecimal number.
jsUtils.isHex( str )
str - any javascript variable
Returns true if the variable is a valid hexadecimal number or false otherwise.
Any input variable is treated as a string. The function will test each charector in this string to be inside the set of A..F, a..f, 0..9.
If all charectors are inside the set, it will return true, otherwise false. This function can be used to verify that a number is a valid
color number, since color numbers are hexidecimal numbers. The number cannot contain dot (.)
Example
<!DOCTYPE html>
<html>
<head>
<script src="system/libs/jsUtils.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function() {
alert(jsUtils.isHex('1d0'));
alert(jsUtils.isHex('AF10'));
}
</script>
<body>
</body>
</html>
See Also