The following example shows how you can prevent a user from pressing Enter in a Flex TextArea control by listening for the textInput event and checking the TextEvent object’s text property for a newline character (”\n”).
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/07/preventing-line-feeds-in-a-textarea-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function textArea_textInput(evt:TextEvent):void {
if (evt.text == "\n") {
evt.preventDefault();
}
}
]]>
</mx:Script>
<mx:TextArea id="textArea"
verticalScrollPolicy="on"
width="160"
height="120"
textInput="textArea_textInput(event);">
<mx:text>The quick brown fox jumped over the lazy dog.</mx:text>
</mx:TextArea>
</mx:Application>
View source is enabled in the following example.





Hi,Peter deHaan
Thanks for your great post!
I have a another question about this.
I use TextArea component in flex, trigger “Ctrl + Enter” event to newline(use this to send messege in my project), but more empty newline in IE(it’s ok in Firefox or trigger ‘Shift+Enter’),how can i solve this problem?
Thank you very much!!!
Code like below
if(evt.ctrlKey == true && evt.keyCode == Keyboard.ENTER) {
……
}
hi dis is manish workin in teknopoint multimedia thanks for givin the source of this code…i was trying to disable the enter key by using ifocus manager bt everythin invain..ur code help me out in dis thanks….
How can I disable backspace, left arrow and right arrow keys ?