I want to limited my input value to 100 only the number entered it should be 0 to 100 and it shouldn't go more then 100 how can I do this
This is The input code
Enter Html Marks.........
<input id="hm" type="tel" size="4" maxlength="3" />
My friend told me about unicode but I don't know anything about unicode please explain about unicode too
I want to limited my input value to 100 only the number entered it should be 0 to 100 and it shouldn't go more then 100 how can I do this
This is The input code
Enter Html Marks.........
<input id="hm" type="tel" size="4" maxlength="3" />
My friend told me about unicode but I don't know anything about unicode please explain about unicode too
Share Improve this question edited Jun 4, 2015 at 13:47 一二三 21.3k11 gold badges69 silver badges75 bronze badges asked Jun 4, 2015 at 7:09 tariq khantariq khan 311 gold badge2 silver badges8 bronze badges 4- Tell your friend to stop messing with you. It has nothing to do with unicode, and it's impossible with pure HTML. You need to use JS validation for this. – Amit Commented Jun 4, 2015 at 7:12
-
@Amit
maxlength
has something to do with unicode, and what the OP wants to do is possible with HTML5 – Kaiido Commented Jun 4, 2015 at 7:23 - @Kaiido can you explain - How does maxlength and unicode relate? (And yes, you're right about HTML5) – Amit Commented Jun 4, 2015 at 7:33
- @Amit well maxLength="x" allows x unicode code points. so if you take a bining character like backtick ` you can actually enter x+1 of them but if you take some posed one like U+E01A5, you will be able to enter only x/2 of them – Kaiido Commented Jun 4, 2015 at 7:50
4 Answers
Reset to default 4You could add an onchange method.
<input id="hm" type="tel" size="4" maxlength="3" onchange="changeHandler(this)"/>
In that changeHandler function you check the value of your input and set it back to 100 if it was higher:
<script>
function changeHandler(val)
{
if (Number(val.value) > 100)
{
val.value = 100
}
}
</script>
Use Pattern Attribute. and put this regex inside "\b(0*(?:[1-9][0-9]?|100))\b"
This has nothing to do with unicode, you can do this by using javascript or jquery.
<input id="hm" type="tel" />
Javascript code :
<script>
document.getElementById("hm").onkeyup=function(){
var input=parseInt(this.value);
if(input<0 || input>100)
alert("Value should be between 0 - 100");
return;
}
</script>
you can put min and max in an input type = number
try this
<input type="number" min="0" max="100" step="1"/>