0
How to make input of number only takes 10 digit. Eg mobile number
15 odpowiedzi
+ 3
maxlength="10" in input tag
+ 3
Yes
+ 3
No😂
+ 1
amith pattern to ensure only digits, tel allow "." and other special characters
+ 1
okay thanks @calvin
+ 1
Yes ,so I coded this but it turns to 0 if number is greater than 10
window.onload=function(){
var c=document.getElementById("num");
c.addEventListener("input",stop,false);
function stop(){
a=this.value.length;
if(a>10){
this.value="0";
}
}
}
But you already got the answer and I didn't knew about that Tel thing and pattern ,so my code won't work when */ are entered
0
max length only work for text right? @Abhay
0
thanku
0
type="Tel" is enough right? @Bartika,Calvin
0
without pattern also it's now got restricted to 10digits.. pattern is mandatory? @Barthika
0
ok thanks @Bartika
0
tanku bro @Abhay
0
It is very easy set maxlength to 10 digits like this
<Input type="tel" name="tel" maxlength ="10" >