HTML text input allow only numeric input

前端 未结 30 3528
孤街浪徒
孤街浪徒 2020-11-21 04:58

Is there a quick way to set an HTML text input () to only allow numeric keystrokes (plus \'.\')?

30条回答
  •  野性不改
    2020-11-21 05:20

    2 solutions:

    Use a form validator (for example with jQuery validation plugin)

    Do a check during the onblur (i.e. when the user leaves the field) event of the input field, with the regular expression:

    
    
    
    

提交回复
热议问题