1. // THIS FUNCTION WILL CHECK A STRING'S CHARCODE'S
  2. //
  3. // IT TAKES 3 PARAMATERS:
  4. // targetInput = THE INPUT TEXT AREA YOU WANT TO TARGET
  5. // targetLabel = THE LABEL YOU WANT TO GIVE YOUR TEXT AREA - USED FOR ERROR MESSAGE
  6. // statusText = THE DYNAMIC TEXT AREA YOU WANT TO DISPLAY YOUR ERROR MESSAGE IN
  7. //
  8. utfChecker = function(targetInput, targetLabel, statusText){
  9.     // STORE THE INPUT TEXT
  10.     var userInput:String = targetInput.text;
  11.     // NOW LET'S CLEAR THE INPUT TEXT AS WE WILL REWRITE IT LATER
  12.     targetInput.text = "";
  13.     // WE NEED TO REWRITE THE TEXT AREA SO LET'S MAKE
  14.     // A VARIABLE TO STORE THE DATA IN
  15.     var newString:String = "";
  16.     // SET MIN RANGE
  17.     var minRange:Number = 31;
  18.     // SET MAX RANGE
  19.     var maxRange:Number = 127;
  20.     // CREATE ERROR MESSAGE ARRAY
  21.     var errorMsg:Array = new Array();
  22.     // DISPLAY ERROR MESSAGE
  23.     var msgDisplay:String;
  24.     targetInput.html = true
  25.     // GET THE LENGTH OF THE USER INPUT TEXT
  26.     var targetInputLength:Number = userInput.length;
  27.     // LOOP THROUGH THE TEXT AND CHECK CHAR CODES
  28.     for (var i:Number = 0; i <targetInputLength; i++) {
  29.         // VALIDATE EACH CHARACTER
  30.         if (userInput.charCodeAt(i) <31 || userInput.charCodeAt(i)> 127) {
  31.             // WE'VE GOT A PROBLEM
  32.             errorMsg.push(userInput.charAt(i));
  33.             newString += "<font color = '#FF0000'><b>" + userInput.charAt(i) + "</b></font>"
  34.         }else{
  35.             newString += userInput.charAt(i);
  36.         }
  37.     }
  38.     trace(newString);
  39.     targetInput.htmlText = newString;
  40.     // CHECK TO SEE IF THERE ARE ANY ERRORS
  41.     if (errorMsg.length> 0){
  42.         // WE FOUND SOME ERRORS
  43.         msgDisplay = targetLabel + " Has a problem. <br>There are bad characters that will stop your PDF from rendering.  They have been highlighted in red";
  44.     }else{
  45.         // WE'RE OK MOVE ALONG...
  46.         msgDisplay = "We're ok.. Continue";
  47.     }
  48.     // SET THE STATUS TEXT
  49.     statusText.html = true;
  50.     statusText.htmlText = msgDisplay;
  51.    
  52. }
  53.  
  54. /* usage
  55. utfChecker(input_txt, "Text Box 1", status_txt);
  56. */