1 Reply Latest reply on Jan 19, 2007 11:44 AM by phi2265

    Problem with Character Codes...

    phi2265 Level 1
      For some reason this just isn't working right. It works for some characters, like "d" is character code 100, it works for 100 but if i put in 104, which is "h" it doesnt work! doesnt work 32 which is space or 33 which is !

      here is my function...

      public function illegalCharCheck(charCheck:String):void{
      var i:int;
      var len:int = charCheck.length;
      for (i = 0; i < len; i++){
      if (charCheck.charCodeAt(i) == 100){
      Alert.show('Illegal Character!', 'Sign Up', mx.controls.Alert.OK);
      }
      }
      }
      Ive tried putting the character being checked for in different spots in the string(which shouldnt matter).
      So far it has not worked with anything other than 100, but i've only tried like 10 or so. It should work for all of them!

      Does anyone have any idea what is going on here?

      Also.. Can i separate the character codes with commas so that i can check them all in one if statement (there are a lot), or do i need different if statements for each.. or use a switch statement. That part isn't really clear to me for some reason...

      Thanks.
        • 1. Re: Problem with Character Codes...
          phi2265 Level 1
          got it... i had the string being imported from newUserNameInput.toString(); instead of newUserNameInput.text

          private var illegalChars:Array = new Array(32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126)

          public function illegalCharCheck(charCheck:String):void{
          var i:int;
          var i2:int;
          var len:int = charCheck.length;
          var illegalTally:int = 0;
          var illegalLen:int = illegalChars.length;
          debug1.text='';
          for (i = 0; i < len; i++){
          for (i2 = 0; i2 < illegalLen; i2++){
          if (charCheck.charCodeAt(i) == illegalChars[i2]){
          debug1.text=debug1.text+charCheck.charCodeAt(i)+' ';
          illegalTally++;
          }
          }
          }
          if (illegalTally>0){
          debug1.text=debug1.text+' tally='+illegalTally;
          Alert.show('Illegal Character! ', 'Sign Up', mx.controls.Alert.OK);
          }
          }


          works like a charm.