How to allow only numeric (0-9) in HTML inputbox using jQuery?

前端 未结 30 2261
一生所求
一生所求 2020-11-21 05:38

I am creating a web page where I have an input text field in which I want to allow only numeric characters like (0,1,2,3,4,5...9) 0-9.

How can I do this using jQuery

30条回答
  •  半阙折子戏
    2020-11-21 05:45

    The pattern attribute in HTML5 specifies a regular expression that the element's value is checked against.

      
    

    Note: The pattern attribute works with the following input types: text, search, url, tel, email, and password.

    • [0-9] can be replaced with any regular expression condition.

    • {1,3} it represents minimum of 1 and maximum of 3 digit can be entered.

提交回复
热议问题