如何在jquery中检查IP地址的有效性 [英] How to check validation of IP Address in jquery

查看:506
本文介绍了如何在jquery中检查IP地址的有效性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在项目中添加IP验证.jquery或jquery mobile中是否有任何功能,以便它将验证输入字段?

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?

谢谢

推荐答案

请参阅此文档 IP验证

在这里他使用了jqueryvalidator.js并举例说明.

here he has used jqueryvalidator.js and explained with example.

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

            $('#form1').validate({
                rules: {
                    ip: {
                        required: true,
                        IP4Checker: true
                    }
                }
            });

这篇关于如何在jquery中检查IP地址的有效性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆