简体   繁体   English

在多行文本框中防止换行

[英]Preventing New line in a multiline text box

How to prevent the new line character at the beginning of the text entering in a multiline text box? 如何防止换行符输入到多行文本框中的文本开头? Now, I already trimmed the white space at the beginning of the text. 现在,我已经修剪了文本开头的空白。 but i can't prevent the new line character that has to be occurred by entering the enter key on the most beginning of the text box. 但是我无法通过在文本框的最开始处输入Enter键来防止必须出现换行符。 Please help me. 请帮我。 thanks in advance. 提前致谢。

Manged code: yourText.Replace(Environment.Newline, String.Empty) 强制代码:yourText.Replace(Environment.Newline,String.Empty)

In JavaScript: Have a look here this is what you are looking for http://www.webtoolkit.info/javascript-trim.html 在JavaScript中:在这里看看,这就是您正在寻找的http://www.webtoolkit.info/javascript-trim.html

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

The following chars as parameters: 以下字符作为参数:

  • “\\n” (ASCII 10 (0×0A)), a new line (line feed). “ \\ n”(ASCII 10(0×0A)),换行(换行)。
  • “\\r” (ASCII 13 (0×0D)), a carriage return. “ \\ r”(ASCII 13(0×0D)),回车符。

You can attach that to the OnChanged event of the textbox. 您可以将其附加到文本框的OnChanged事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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