0

Requirement: I want it to do dynamically. I do not want the user to see a special character entered into the textBox. Instead of the special character the user should see only a blank space entered in the place of the special character. Is it possible to do such event. I tried many ways but could not achieve it. Its is very challenging , someone please help me

MXML Code:

<mx:TextInput x="10" y="25" id="txtSearch" width="200" enter="btnSearch_Click();" keyDown="txtSearch_KeyUpHandler(event);"/>

AS Code:

private function txtSearch_KeyUpHandler(event:KeyboardEvent):void {
    if(!((event.charCode >= 48 && event.charCode <= 57)||(event.charCode >= 65 && event.charCode <= 90)||(event.charCode >= 97 && event.charCode <= 112)))
    {
        //event.preventDefault();
        event.charCode = 32;
    }
}

When I execute the above code, it did not execute as expected. The special characters are being entered in the txtSearch text box. I am not sure about what has went wrong here. Can you please help me. Thanks in Advance

Dinesh Kumar
  • 1,469
  • 4
  • 27
  • 46
  • try `textInput="Myfun(event)"` event instead keyDown – Santhosh Nayak Jul 17 '12 at 08:41
  • I have tried even the following code : private function txtSearch_KeyUpHandler(event:KeyboardEvent):void { if(!((event.charCode >= 48 && event.charCode <= 57)||(event.charCode >= 65 && event.charCode <= 90)||(event.charCode >= 97 && event.charCode <= 112))) { var lastIndex:int = txtSearch.text.length-1; var Str:String = txtSearch.text.charAt(lastIndex); var Str2:String = Str.charAt(lastIndex); txtSearch.text = txtSearch.text.replace(Str2,"_"); //event.preventDefault(); //event.charCode = 32; } } – Dinesh Kumar Jul 18 '12 at 10:27

1 Answers1

1

The solution of the above is

at the enter function loop the text entered, and

search for special character and replace with by space.

Its better to use the regular expression on the enter click.

Community
  • 1
  • 1
Exhausted
  • 1,867
  • 2
  • 23
  • 33