Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.91 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $.validator.addMethod("phrange", function (value, element) {
  2.         if( $(element).attr('placeholder') === value ){
  3.                 return true;
  4.         }
  5.         return $.validator.methods.range.apply(this,arguments);
  6. }, "");
  7.  
  8. $.validator.addMethod("qq", function (value, element) {
  9.         if( $(element).attr('placeholder') === value ){
  10.                 return true;
  11.         }
  12.         return (value.length >= 5 && value.length <= 11 && $.validator.methods.digits.apply(this,arguments))
  13.                 ||      $.validator.methods.email.apply(this,arguments)        
  14. }, "必须为QQ数字或邮箱帐号");
  15.  
  16. $.validator.addMethod("mobile", function (value, element) {
  17.         return this.optional(element) || /^1[3458](\d){9,9}$/i.test(value);
  18. }, "格式不对哦,请重新输入,必须为11位手机号码");
  19.  
  20. $.validator.addMethod("birth", function (value, element) {
  21.         var explict = $.grep(value.split(','),Boolean);
  22.         // 默认可选
  23.         if(explict.length !== 3) return true;
  24.  
  25.         var now = new Date(), select = new Date(explict[0], explict[1]-1, explict[2])
  26.         var is_future = select-now>0;
  27.  
  28.         // console.log(explict,now,is_future);
  29.         return !is_future;
  30. }, "不能出生在未来哦");
  31.  
  32. // http://forum.jquery.com/topic/jquery-validate-remote-vs-depends
  33. // remote和depends搭配时有bug.
  34. $.validator.addMethod("xremote", function(value, element) {
  35.     var rule = this.settings.rules[element.name].xremote;
  36.     if (rule.condition && $.isFunction(rule.condition) && !rule.condition.call(element,this))
  37.         return "dependency-mismatch";
  38.     return $.validator.methods.remote.apply(this, arguments);
  39. }, $.validator.messages.remote);
  40.  
  41. // remote不能扩展动态的提交参数,同步检验方法:(会造成UI锁住)
  42. $.validator.addMethod("uniqueDomain", function (value, element) {
  43.         if(element.value == element.defaultValue){
  44.                 return true;
  45.         }
  46.         var xhr = $.ajax({
  47.                 url:'/ajax/checkDomain',
  48.                 async : true,
  49.                 data : {
  50.                    domain : value
  51.                 }
  52.         });
  53.         var resp = xhr.responseText;
  54.         return !resp && resp !== 'true';
  55. }, "域名已被占用,换一个吧");