JavaScript to accept only numbers between 0 to 255 range

后端 未结 8 1649
野趣味
野趣味 2021-01-22 13:14

My Requirement is to validate the ip ranges, I need to create a JavaScript function to accept only numeric and it must allow only between the range 0 to 255. If anything is ente

8条回答
  •  一向
    一向 (楼主)
    2021-01-22 13:37

    You need to validate the current value of the input, rather than the last key that was pressed:

     
    

    Your function then just needs to be modified to: if(a < 0 || a > 255)

提交回复
热议问题