html - How to set the limit for multiline textbox in asp.net -


I am using multiline textbox , now I want to allow all the characters in it And I also want to use the regular expression to set the limit of text box to 150 characters so that anyone can help me I am using this regular expression:

  "^ [A-Za-z0- 9 \ s! @ # $% ^ & Amp; (; _ _ = ~ ~ ~ \\\] <[{}} '' :::???? Gt; & lt;] * {1,150} $ " 

All work A but it does not limit the characters to 150

Thanks in advance.

It's really easy to do this: New browser

, But the maximum length on textarea elements (but not older versions of IE9 and Internet Explorer) or at least characters Get count of if you want to show "X face balance" (like posting a comment in SO).

For older browsers this will check against javascript maximum length and will prevent the user from typing. However, since users can potentially defeat the keydown approach via copy and paste, so using keyup to reduce any overflow is a Good idea, apart from this, if the data is going into the server / database then removing the input from the client and making it sanitized is not a bad idea, if the client bypasses the form and uploads the post data directly Literacy is in that case maxlength has no effect.

ASP.NET looks like a markup: & lt; Asp: textbox id = "txt" runat = "server" textmode = "multiline" client idode = "static" maxlength = "150 textarea (TextMode =" Multiline ") for The maxlength attribute can not be rendered (perhaps depending on your ASP.NET version). You can verify in the markup that it was sung. If not, then you will see the text box in the code box < Code> attributes may be required to manipulate: txt.Attributes ["maxlength"] = "150"; (assuming C #)

JS Fiddle example :

  / "Maxlength" code for previous browsers including IE9 and previous versions var txt = document.getElementById ('txt'); txt.onkeyup = function () {var maxlength = parseInt (Get.ttAttribute ("maxlength")) || 0; if (Mactland & gt; 0 & amp; amp; amp; this.value.length & gt; maximum length) {this.value = this.value.substring (0, max length); Warning ('text was truncated to' max-length + 'characters.'); } Document.getElementById ('length'). InnerHTML = this.value.length.toString (); }; Txt.onkeydown = function () {var maxlength = parseInt (this.getAttribute ("maxlength")) || 0; If (Mactland & gt; 0 & amp; amp; amp; amp; amp; amp; this.value lambia = maxlength & amp; event.keyCode; event.which) & gt; ; 49) {return false; }};  
  & lt; Div & gt; Characters: & lt; Span id = 'length' & gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; Textarea id = 'txt' maxlength = '150' & gt; & Lt; / Textarea & gt;  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -