/ Published in: ActionScript 3
Expand |
Embed | Plain Text
public class HexUtils { public static const HEX_64_BITS:int = 10; public static const HEX_128_BITS:int = 26; public static function isValidHex(_val:String, ...args:Array):Boolean { //splice the 0x if it's there if(_val.substr(0, 2)=="0x") _val = _val.substr(2); //this part is not tested var length:Array = [HEX_64_BITS, HEX_128_BITS]; if(args.length>0) { if(args[0] is Array) { length = args[0]; } else { length = [args[0]]; } } //test with hex char if(length.indexOf(_val.length)>-1) { if(_val.match(/^[A-Fa-f0-9]*$/)) { return true; } } return false; } } TESTING: var hexToTest:Array = ['0x1122334455', '1122334455', '0x112233445', '0xabcde12345', '0xz123456789', '0xabcdeaaaaa']; for each(var hex:String in hexToTest) { trace('isHexValid', hex, HexUtils.isValidHex(hex)); }
You need to login to post a comment.
