我有一个文本字段。 我想让这个字段只接受10位数,如果输入的数字大于10或小于10,则抛出错误
<td><input name="Number" type="text" id="Number" value="" required/></td>
document.getElementById('Number').onchange = function()
{
if(this.value > 11){
this.value = "Please Check the Ticket Number Again";
}
if(this.value < 10){
this.value = "Please Check the Ticket Number Again";
}
}
答案 0 :(得分:1)
试试这段代码:
<td><input name="Number" type="text" id="Number" value="" required/></td>
document.getElementById('Number').onchange = function()
{
if(this.value.length != 10){
this.value = "Please Check the Ticket Number Again";
}
}