How to restrict user input character length of HTML5 input type=“number”?

前端 未结 4 419
自闭症患者
自闭症患者 2021-01-13 11:44

How do I restrict user input to a given length in an HTML5 input[type=number] textbox?

the answers to

How can I limit possible inputs in a HTML

4条回答
  •  情歌与酒
    2021-01-13 12:29

    to dynamically set max limit

    function limit(element,max_chars) {
    
      if(element.value.length > max_chars) {
        element.value = element.value.substr(0, max_chars);
      }
    }
    
    
    
    

提交回复
热议问题