Validate <input type=“number” /> with AngularJS and Pattern/RegEx

前端 未结 4 2026
野趣味
野趣味 2021-01-12 11:36

I have a input of type number, and I want to make sure it only accepts a number. I can do this fine on the Server side, but with AngularJS I can not get it to work.

4条回答
  •  耶瑟儿~
    2021-01-12 11:46

    Here is regexp to validate floating point numbers, both positive and negative:

    /^-?[0-9]\d*(\.\d+)?$/
    

    Use this regexp in 'text' input, example:

    
    

提交回复
热议问题