开发者

Preventing New line in a multiline text box

开发者 https://www.devze.com 2022-12-22 21:05 出处:网络
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\'tprevent the new li

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 oc开发者_StackOverflow社区curred by entering the enter key on the most beginning of the text box. Please help me. thanks in advance.


Manged code: 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

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).
  • “\r” (ASCII 13 (0×0D)), a carriage return.

You can attach that to the OnChanged event of the textbox.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号