|
May
06
|
Just now I was trying to restrict the backslash input in textbox in flash. Many I have tried, none successful. Good that I came across this post eventually, and it helps a LOT.
The original documentation in flash is stated as such :
"You can use a backslash to enter a ^ or – verbatim. The accepted backslash sequences are \-, \^ or \\. The
backslash must be an actual character in the string, so when specified in ActionScript, a double backslash must be used. "
That is so…..unclear……
Therefore when u try to restrict the "\", u end up have to use "^\\\\".
e.g. input_txt.restrict = "^\\\\"
********************************
Sometimes when you need to save the data from flash to XML, certain special characters should be taken care of. In XML, ‘<’, ‘>’, ‘/’ and ‘"’ all has its special/reserved meaning. The way I did is to convert those characters to a even more "special" character, that hopefully user wont type out from keyboard.
public static function encodeSpecialChars(str:String):String { var len:Number = str.length; for(var i:Number=0; i<len; i++) { switch (str.charAt(i)) { case "<": str = str.slice(0, i) + String.fromCharCode(170) + str.slice(i+1, len); break; case ">": str = str.slice(0, i) + String.fromCharCode(176) + str.slice(i+1, len); break; case "/": str = str.slice(0, i) + String.fromCharCode(178) + str.slice(i+1, len); break; case "\"": str = str.slice(0, i) + String.fromCharCode(179) + str.slice(i+1, len); break; case "\"": str = str.slice(0, i) + String.fromCharCode(164) + str.slice(i+1, len); break; default: break; } } return str; } public static function decodeSpecialChars(str:String):String { var len:Number = str.length; for(var i:Number=0; i<len; i++) { switch (str.charAt(i)) { case String.fromCharCode(170): str = str.slice(0, i) + "<" + str.slice(i+1, len); break; case String.fromCharCode(176): str = str.slice(0, i) + ">" + str.slice(i+1, len); break; case String.fromCharCode(178): str = str.slice(0, i) + "/" + str.slice(i+1, len); break; case String.fromCharCode(179): str = str.slice(0, i) + "\"" + str.slice(i+1, len); break; case String.fromCharCode(164): str = str.slice(0, i) + "\"" + str.slice(i+1, len); break; default: break; } } return str; }
Recent Comments