一个方便判断验证的小方法

var failed = validate("need name!", $('#name').val())
	.validate("need age!", $('#age').val())
	.validate("email invlidate!", /\w+@(\w+.)+\w+/.test($('#email').val()))
	.failed;
	
if(failed) {
	alert(failed);
	return false;
}
	
alert("validate success!");




function validate(msg, condition, __result) {
	var result = {
		failed : __result? __result:(condition? null: msg),
		validate: function (_msg, _condition) {
			return validate(_msg, _condition, result.failed);
		}
	};
	return result;
}

  

posted on 2013-12-16 13:07  撒尿去了  阅读(83)  评论(0)    收藏  举报

导航