---
title: "扩展easyui的validatebox，添加验证两次密码功能"
author: "sphsyv23"
date: "2012-09-03T11:29:38Z"
tags: []
categories: ["Web前端"]
slug: "easyui-validatebox"
draft: false
lastmod: "2012-09-03T11:31:36Z"
id: 1670160
url: "https://yusun.iteye.com/blog/1670160"
---

```
/**
 * @author 孙宇
 * 
 * @requires jQuery,EasyUI
 * 
 * 扩展validatebox，添加验证两次密码功能
 */
$.extend($.fn.validatebox.defaults.rules, {
	eqPassword : {
		validator : function(value, param) {
			return value == $(param[0]).val();
		},
		message : '密码不一致！'
	}
});
```

 先扩展validatebox

使用的时候，

```
<form id="modifyPwdForm" method="post">

			<input name="ids" type="hidden" />

			<table class="tableForm">

				<tr>

					<th>新密码</th>

					<td><input name="cpwd" type="password" class="easyui-validatebox" required="true" missingMessage="请填写新密码" /></td>

				</tr>

				<tr>

					<th>重复</th>

					<td><input name="recpwd" type="password" class="easyui-validatebox" required="true" missingMessage="请再次填写新密码" validType="eqPassword['#modifyPwdForm input[name=cpwd]']" /></td>

				</tr>

			</table>

		</form>
```

 

![](http://dl.iteye.com/upload/attachment/0073/2314/c741b874-a1b1-3f3d-b61c-c0312bae5fe5.bmp)