---
title: "自定义验证"
author: "ThinkGoogle"
date: "2012-10-10T09:26:07Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2012-10-10T09:26:07Z"
id: 1694827
url: "https://thinkgoogle.iteye.com/blog/1694827"
---

```
$.extend($.fn.validatebox.defaults.rules, {   
    equals: {   
        validator: function(value,param){   
            return value == $('#newPwd').val();   
        },   
        message: '前后输入新密码不一致'  
    },
    account:{
    	validator: function(value,param){
    		if(value.length < param[0] || value.length > param[1]){
    			$.fn.validatebox.defaults.rules.account.message = '用户名长度必须在'+param[0]+'至'+param[1]+'位字符';
    			return false;
    		}else{
    			if(!/^[\w]+$/.test(value)){
    				$.fn.validatebox.defaults.rules.account.message = '用户名只能是数字、字母、下划线';
    				return false;
    			}else{
    				return true;
    			}
    		}
    	},
    	message:''
    }

});
```