Skip to content Skip to sidebar Skip to footer

How To Apply Min And Max On Textarea?

Is there a way in HTML5 forms to add a min and max character to a textarea? It seems I can apply it to a regular input using pattern.
<form><textareamaxlength="20"minlength="5"></textarea><inputtype="submit"value="Check"></input></form>

Solution 2:

For max: see below code Use maxlength for maximum character.

maxlength="nuber_of_characters"

Source: http://www.w3.org/TR/html5/forms.html#the-textarea-element

For min:source Use Javascript as below: use id attribute in <textarea>. Set id attribute to minle(for eg) ie id="minle"

<textarea rows="10" cols="80" maxlength="200" required id="minle" >
</textarea> 

and put following js code segment in your form tag

  <form action="mango.php" method="post"id="form12" onsubmit="var text = document.getElementById('minle').value; if(text.length < 80) { alert('put more info!'); return false; } return true;">

This allow user to input no. of characters from 80 to 200.

Solution 3:

HTML5 solution, min 5, max 10 characters

http://jsfiddle.net/xhqsB/102/

<form><inputpattern=".{5,10}"><inputtype="submit"value="Check"></input></form>

Solution 4:

You can use minlength=20. Do not use "".

For exp true: minlength=20 False exp: minlength="20"

Post a Comment for "How To Apply Min And Max On Textarea?"