JavaScript to accept only numbers between 0 to 255 range

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

        function fun_key()
        {
        var key=event.keyCode;
        if(key>=48 && key<=57)
        {
        return true;
        }
        else
        {
        return false;
        alert("please enter only number");
        }
        }
    
        and you can call this function on keypress event like:
                        
    

提交回复
热议问题