简体   繁体   中英

In Flex- special characters entered in TxtBox should be replaced with a blank space

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM