Maximum text length?

Is it possible to set the maximum length of text in TextArea ?

+4
source share
5 answers

If you are using jQuery, use this plugin http://www.stjerneman.com/demo/maxlength-with-jquery

+2
source

Something interesting is that HTML5 added a maxlength function to textarea if HTML5 is something you can use right now.

White Paper W3C

Demo:

 <textarea maxlength="20"></textarea> 
+9
source

You can use the following format in HTML

 <input type="text" maxlength="13"> 
+3
source

This solution can be reused for all text areas with a single function and it does not inform the user that he is typing too many characters, this prevents them from doing this, sort of like maxlength

Function:

 <script language="javascript" type="text/javascript"> function imposeMaxLength(Object, MaxLen) { return (Object.value.length <= MaxLen); } </script> 

Implementation:

 <textarea name="myName" onkeypress="return imposeMaxLength(this, 15);" ><textarea> 
+2
source

Textarea does not accept the maximum length.

I created a javascript function to handle this onchange event. On one of my solutions, I avoid sending onsubmit events in the form.

The code below will not be sent if the text field has more than 255 characters

 <script> function checkSize(){ var x = document.getElementById('x'); return x.value.length <= 255; } </script> <form onsubmit="return checkSize()"> <textarea id="x"><textarea> </form> 
+1
source

Source: https://habr.com/ru/post/1341280/


All Articles