---
title: "jQuery Validate 扩展IP校验"
author: "xplazy"
date: "2009-03-08T17:42:41Z"
tags: []
slug: "jquery-validate-ip"
draft: false
lastmod: "2009-03-08T17:43:26Z"
id: 345455
url: "https://xplazy.iteye.com/blog/345455"
---

jQuery Validate 扩展对IP校验的支持。大家有空帮忙测试。哈。

 

```
	jQuery.validator.addMethod("ip", function(value, element) { 
	  return this.optional(element) || (/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.test(value) && (RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)); 
	}, "请输入合法的IP信息");
```