function - How can I check if a string contains an hexadecimal value in VBScript? -
is there function in vbscript check if string contains valid hexadecimal value?
for example:
dim x : x = ishexadecimal("2af3") 'x = true dim y : y = ishexadecimal("x2m3") 'y = false
you use regular expression, others have suggested:
function ishexadecimal(byval v) set re = new regexp re.pattern = "^[a-f0-9]+$" re.ignorecase = true ishexadecimal = re.test(v) end function another solution (with little more hack value):
function ishexadecimal(byval v) on error resume next dim : = clng("&h" & v) ishexadecimal = not isempty(i) on error goto 0 end function
Comments
Post a Comment