How to check validation of IP Address in jquery

前端 未结 9 1775
挽巷
挽巷 2021-01-17 21:39

I need to add IP Validation in my project .Is there any function in jquery or in jquery mobile.So that it will validate the in put field?

Thanks

9条回答
  •  无人及你
    2021-01-17 22:10

    Addition to answer by @RAVI MONE for IP address with subnet mask:

    $.validator.addMethod('IP4Checker', function(value) {
        var ip="^$|([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
          "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
          "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
          "([01]?\\d\\d?|2[0-4]\\d|25[0-5])((/([01]?\\d\\d?|2[0-4]\\d|25[0-5]))?)$";
        return value.match(ip);
    }, 'Invalid IP address.');
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题