Check if a textbox contains numbers only

后端 未结 5 1822
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 06:38

How to check if a textbox contains numbers only?

While googling I came across this. But I\'m wondering if isNumeric can be used for this purpose or if t

5条回答
  •  借酒劲吻你
    2020-12-10 07:29

    using pure JS regular expression

     var query = document.getElementById('myText').value;
     var isNumeric=query.match(/^\d+$/);
      if(isNumeric){/*...*/}else{/*...*/}
    

    or using html5 control

     
    

提交回复
热议问题