Created
August 10, 2011 09:35
-
-
Save ambar/1136453 to your computer and use it in GitHub Desktop.
$.validator.methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.validator.addMethod("phrange", function (value, element) { | |
if( $(element).attr('placeholder') === value ){ | |
return true; | |
} | |
return $.validator.methods.range.apply(this,arguments); | |
}, ""); | |
$.validator.addMethod("qq", function (value, element) { | |
if( $(element).attr('placeholder') === value ){ | |
return true; | |
} | |
return (value.length >= 5 && value.length <= 11 && $.validator.methods.digits.apply(this,arguments)) | |
|| $.validator.methods.email.apply(this,arguments) | |
}, "必须为QQ数字或邮箱帐号"); | |
$.validator.addMethod("mobile", function (value, element) { | |
return this.optional(element) || /^1[3458](\d){9,9}$/i.test(value); | |
}, "格式不对哦,请重新输入,必须为11位手机号码"); | |
$.validator.addMethod("birth", function (value, element) { | |
var explict = $.grep(value.split(','),Boolean); | |
// 默认可选 | |
if(explict.length !== 3) return true; | |
var now = new Date(), select = new Date(explict[0], explict[1]-1, explict[2]) | |
var is_future = select-now>0; | |
// console.log(explict,now,is_future); | |
return !is_future; | |
}, "不能出生在未来哦"); | |
// http://forum.jquery.com/topic/jquery-validate-remote-vs-depends | |
// remote和depends搭配时有bug. | |
$.validator.addMethod("xremote", function(value, element) { | |
var rule = this.settings.rules[element.name].xremote; | |
if (rule.condition && $.isFunction(rule.condition) && !rule.condition.call(element,this)) | |
return "dependency-mismatch"; | |
return $.validator.methods.remote.apply(this, arguments); | |
}, $.validator.messages.remote); | |
// remote不能扩展动态的提交参数,同步检验方法:(会造成UI锁住) | |
$.validator.addMethod("uniqueDomain", function (value, element) { | |
if(element.value == element.defaultValue){ | |
return true; | |
} | |
var xhr = $.ajax({ | |
url:'/ajax/checkDomain', | |
async : true, | |
data : { | |
domain : value | |
} | |
}); | |
var resp = xhr.responseText; | |
return !resp && resp !== 'true'; | |
}, "域名已被占用,换一个吧"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment