JavaScript to accept only numbers between 0 to 255 range

后端 未结 8 1577
野趣味
野趣味 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:42

    A function like this should do it:

    function allownums(value){
       var num = parseInt(value,10);
       if(num <0 || num>255)
          alert('invalid')      
    }
    

    Then have your html look like:

     
    

    Live example: http://jsfiddle.net/USL3E/

提交回复
热议问题