Home Downloads YUI 和 jQuery 版本的 Validator 校验框架

YUI 和 jQuery 版本的 Validator 校验框架

Validator v1.0
身份证号码如:420105198309113219
您还可以输入300个字

jQuery 版本

var idType = $('#card-type')[0], 
		Validator = jQuery.Validator, 
		validateSelectWithIdCard = function(){
		var val = parseInt(idType.value, 10), cardOption = {
			"target": "id-card",
			"rule": "idcard",
			"tipCnt": "idcard-txt"
		}, anyOption = {
			"target": "id-card",
			"rule": "require",
			"tipCnt": "idcard-txt"
		};
		
		switch (val) {
			case 1:
				Validator.add(cardOption);
				if (Validator.indexOf(Validator.options, anyOption) > -1) {
					Validator.remove(anyOption);
				}
				break;
			case 2:
				Validator.add(anyOption);
				if (Validator.indexOf(Validator.options, cardOption) > -1) {
					Validator.remove(cardOption);
				}
				
		}
	};
	
	validateSelectWithIdCard();	
    $(idType).change(function(){
		validateSelectWithIdCard();
	});	
	
	Validator.setup({
		"form": "validator-form"
	}).add({
	    "target": "username",
		"rule": "username",
		"action": "username.html",
		"error": "对不起,此用户名已经被使用过!请更换一个!"
	}).add({
		"target": "password",
		"rule": "password",
		"plus": true
	}).add({
		"target": "confirm-password",
		"rule": "password",
        "to": "password" 
	}).add({
		"target": "age",
		"rule": "number"
	}).add({
		"target": "age",
		"rule": "number"
	}).add({
		"target": "birthday",
		"rule": "date"
	}).add({
		"target": "card-type",
		"rule": "require"
	}).add({
		"target": "email",
		"rule": "email"
	}).add({
		"target": "qq",
		"rule": "qq"
	}).add({
		"target": "telephone",
		"rule": "phone"
	}).add({
		"target": "mobile",
		"rule": "mobile"
	}).add({
		"target": "phone",
		"rule": "phone||mobile",
		"tips": "请输入您的手机或座机电话号码!",
		"warn": "您输入的联系电话号码格式不正确!"
	}).add({
		"target": "zip-code",
		"rule": "zip"
	}).add({
		"target": "ip-address",
		"rule": "ip"
	}).add({
		"target": "url",
		"rule": "url"
	}).add({
		"target": "message",
		"rule": "require",
		"plus": function(){
			var cmt = $('#message')[0], 
			    counter = $('#text-counter')[0], 
				len = cmt.value.length, 
				max = 300,
				val = max - len;
				
			if (val >= 0) {
				counter.innerHTML = val;
			}
			else {
			    cmt.value = cmt.value.substring(0, max); 
			}
		}
	});

下载地址:Validator.zip

Facebook Twitter Delicious 开心网 人人网 豆瓣网 新浪微博 网易微博 腾讯微博