jquery2.validate.min.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*! jQuery Validation Plugin - v1.14.0 - 6/30/2015
  2. * http://jqueryvalidation.org/
  3. * Copyright (c) 2015 J枚rn Zaefferer; Licensed MIT */
  4. ! function(a) {
  5. "function" == typeof define && define.amd ? define(["jquery"], a) : a(jQuery)
  6. }(function(a) {
  7. a.extend(a.fn, {
  8. validate: function(b) {
  9. if (!this.length) return void(b && b.debug && window.console && console.warn(
  10. "Nothing selected, can't validate, returning nothing."));
  11. var c = a.data(this[0], "validator");
  12. return c ? c : (this.attr("novalidate", "novalidate"), c = new a.validator(b, this[0]), a
  13. .data(this[0], "validator", c), c.settings.onsubmit && (this.on("click.validate",
  14. ":submit",
  15. function(b) {
  16. c.settings.submitHandler && (c.submitButton = b.target), a(this)
  17. .hasClass("cancel") && (c.cancelSubmit = !0), void 0 !== a(this)
  18. .attr("formnovalidate") && (c.cancelSubmit = !0)
  19. }), this.on("submit.validate", function(b) {
  20. function d() {
  21. var d, e;
  22. return c.settings.submitHandler ? (c.submitButton && (d = a(
  23. "<input type='hidden'/>").attr("name", c
  24. .submitButton.name).val(a(c.submitButton).val())
  25. .appendTo(c.currentForm)), e = c.settings.submitHandler
  26. .call(c, c.currentForm, b), c.submitButton && d.remove(),
  27. void 0 !== e ? e : !1) : !0
  28. }
  29. return c.settings.debug && b.preventDefault(), c.cancelSubmit ? (c
  30. .cancelSubmit = !1, d()) : c.form() ? c.pendingRequest ? (c
  31. .formSubmitted = !0, !1) : d() : (c.focusInvalid(), !1)
  32. })), c)
  33. },
  34. valid: function() {
  35. var b, c, d;
  36. return a(this[0]).is("form") ? b = this.validate().form() : (d = [], b = !0, c = a(this[0]
  37. .form).validate(), this.each(function() {
  38. b = c.element(this) && b, d = d.concat(c.errorList)
  39. }), c.errorList = d), b
  40. },
  41. rules: function(b, c) {
  42. var d, e, f, g, h, i, j = this[0];
  43. if (b) switch (d = a.data(j.form, "validator").settings, e = d.rules, f = a.validator
  44. .staticRules(j), b) {
  45. case "add":
  46. a.extend(f, a.validator.normalizeRule(c)), delete f.messages, e[j.name] = f, c
  47. .messages && (d.messages[j.name] = a.extend(d.messages[j.name], c
  48. .messages));
  49. break;
  50. case "remove":
  51. return c ? (i = {}, a.each(c.split(/\s/), function(b, c) {
  52. i[c] = f[c], delete f[c], "required" === c && a(j).removeAttr(
  53. "aria-required")
  54. }), i) : (delete e[j.name], f)
  55. }
  56. return g = a.validator.normalizeRules(a.extend({}, a.validator.classRules(j), a.validator
  57. .attributeRules(j), a.validator.dataRules(j), a.validator.staticRules(j)), j), g
  58. .required && (h = g.required, delete g.required, g = a.extend({
  59. required: h
  60. }, g), a(j).attr("aria-required", "true")), g.remote && (h = g.remote, delete g.remote,
  61. g = a.extend(g, {
  62. remote: h
  63. })), g
  64. }
  65. }), a.extend(a.expr[":"], {
  66. blank: function(b) {
  67. return !a.trim("" + a(b).val())
  68. },
  69. filled: function(b) {
  70. return !!a.trim("" + a(b).val())
  71. },
  72. unchecked: function(b) {
  73. return !a(b).prop("checked")
  74. }
  75. }), a.validator = function(b, c) {
  76. this.settings = a.extend(!0, {}, a.validator.defaults, b), this.currentForm = c, this.init()
  77. }, a.validator.format = function(b, c) {
  78. return 1 === arguments.length ? function() {
  79. var c = a.makeArray(arguments);
  80. return c.unshift(b), a.validator.format.apply(this, c)
  81. } : (arguments.length > 2 && c.constructor !== Array && (c = a.makeArray(arguments).slice(1)), c
  82. .constructor !== Array && (c = [c]), a.each(c, function(a, c) {
  83. b = b.replace(new RegExp("\\{" + a + "\\}", "g"), function() {
  84. return c
  85. })
  86. }), b)
  87. }, a.extend(a.validator, {
  88. defaults: {
  89. messages: {},
  90. groups: {},
  91. rules: {},
  92. errorClass: "error",
  93. validClass: "valid",
  94. errorElement: "label",
  95. focusCleanup: !1,
  96. focusInvalid: !0,
  97. errorContainer: a([]),
  98. errorLabelContainer: a([]),
  99. onsubmit: !0,
  100. ignore: ":hidden",
  101. ignoreTitle: !1,
  102. onfocusin: function(a) {
  103. this.lastActive = a, this.settings.focusCleanup && (this.settings.unhighlight && this
  104. .settings.unhighlight.call(this, a, this.settings.errorClass, this.settings
  105. .validClass), this.hideThese(this.errorsFor(a)))
  106. },
  107. onfocusout: function(a) {
  108. this.checkable(a) || !(a.name in this.submitted) && this.optional(a) || this.element(a)
  109. },
  110. onkeyup: function(b, c) {
  111. var d = [16, 17, 18, 20, 35, 36, 37, 38, 39, 40, 45, 144, 225];
  112. 9 === c.which && "" === this.elementValue(b) || -1 !== a.inArray(c.keyCode, d) || (b
  113. .name in this.submitted || b === this.lastElement) && this.element(b)
  114. },
  115. onclick: function(a) {
  116. a.name in this.submitted ? this.element(a) : a.parentNode.name in this.submitted && this
  117. .element(a.parentNode)
  118. },
  119. highlight: function(b, c, d) {
  120. "radio" === b.type ? this.findByName(b.name).addClass(c).removeClass(d) : a(b).addClass(
  121. c).removeClass(d)
  122. },
  123. unhighlight: function(b, c, d) {
  124. "radio" === b.type ? this.findByName(b.name).removeClass(c).addClass(d) : a(b)
  125. .removeClass(c).addClass(d)
  126. }
  127. },
  128. setDefaults: function(b) {
  129. a.extend(a.validator.defaults, b)
  130. },
  131. messages: {
  132. required: "This field is required.",
  133. remote: "Please fix this field.",
  134. email: "Please enter a valid email address.",
  135. url: "Please enter a valid URL.",
  136. date: "Please enter a valid date.",
  137. dateISO: "Please enter a valid date ( ISO ).",
  138. number: "Please enter a valid number.",
  139. digits: "Please enter only digits.",
  140. creditcard: "Please enter a valid credit card number.",
  141. equalTo: "Please enter the same value again.",
  142. maxlength: a.validator.format("Please enter no more than {0} characters."),
  143. minlength: a.validator.format("Please enter at least {0} characters."),
  144. rangelength: a.validator.format("Please enter a value between {0} and {1} characters long."),
  145. range: a.validator.format("Please enter a value between {0} and {1}."),
  146. max: a.validator.format("Please enter a value less than or equal to {0}."),
  147. min: a.validator.format("Please enter a value greater than or equal to {0}.")
  148. },
  149. autoCreateRanges: !1,
  150. prototype: {
  151. init: function() {
  152. function b(b) {
  153. var c = a.data(this.form, "validator"),
  154. d = "on" + b.type.replace(/^validate/, ""),
  155. e = c.settings;
  156. e[d] && !a(this).is(e.ignore) && e[d].call(c, this, b)
  157. }
  158. this.labelContainer = a(this.settings.errorLabelContainer), this.errorContext = this
  159. .labelContainer.length && this.labelContainer || a(this.currentForm), this
  160. .containers = a(this.settings.errorContainer).add(this.settings
  161. .errorLabelContainer), this.submitted = {}, this.valueCache = {}, this
  162. .pendingRequest = 0, this.pending = {}, this.invalid = {}, this.reset();
  163. var c, d = this.groups = {};
  164. a.each(this.settings.groups, function(b, c) {
  165. "string" == typeof c && (c = c.split(/\s/)), a.each(c, function(a, c) {
  166. d[c] = b
  167. })
  168. }), c = this.settings.rules, a.each(c, function(b, d) {
  169. c[b] = a.validator.normalizeRule(d)
  170. }), a(this.currentForm).on("focusin.validate focusout.validate keyup.validate",
  171. ":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], [type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], [type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], [type='radio'], [type='checkbox']",
  172. b).on("click.validate", "select, option, [type='radio'], [type='checkbox']", b),
  173. this.settings.invalidHandler && a(this.currentForm).on("invalid-form.validate", this
  174. .settings.invalidHandler), a(this.currentForm).find(
  175. "[required], [data-rule-required], .required").attr("aria-required", "true")
  176. },
  177. form: function() {
  178. return this.checkForm(), a.extend(this.submitted, this.errorMap), this.invalid = a
  179. .extend({}, this.errorMap), this.valid() || a(this.currentForm).triggerHandler(
  180. "invalid-form", [this]), this.showErrors(), this.valid()
  181. },
  182. checkForm: function() {
  183. this.prepareForm();
  184. for (var a = 0, b = this.currentElements = this.elements(); b[a]; a++) this.check(b[a]);
  185. return this.valid()
  186. },
  187. element: function(b) {
  188. var c = this.clean(b),
  189. d = this.validationTargetFor(c),
  190. e = !0;
  191. return this.lastElement = d, void 0 === d ? delete this.invalid[c.name] : (this
  192. .prepareElement(d), this.currentElements = a(d), e = this.check(d) !== !1, e ?
  193. delete this.invalid[d.name] : this.invalid[d.name] = !0), a(b).attr(
  194. "aria-invalid", !e), this.numberOfInvalids() || (this.toHide = this.toHide.add(
  195. this.containers)), this.showErrors(), e
  196. },
  197. showErrors: function(b) {
  198. if (b) {
  199. a.extend(this.errorMap, b), this.errorList = [];
  200. for (var c in b) this.errorList.push({
  201. message: b[c],
  202. element: this.findByName(c)[0]
  203. });
  204. this.successList = a.grep(this.successList, function(a) {
  205. return !(a.name in b)
  206. })
  207. }
  208. this.settings.showErrors ? this.settings.showErrors.call(this, this.errorMap, this
  209. .errorList) : this.defaultShowErrors()
  210. },
  211. resetForm: function() {
  212. a.fn.resetForm && a(this.currentForm).resetForm(), this.submitted = {}, this
  213. .lastElement = null, this.prepareForm(), this.hideErrors();
  214. var b, c = this.elements().removeData("previousValue").removeAttr("aria-invalid");
  215. if (this.settings.unhighlight)
  216. for (b = 0; c[b]; b++) this.settings.unhighlight.call(this, c[b], this.settings
  217. .errorClass, "");
  218. else c.removeClass(this.settings.errorClass)
  219. },
  220. numberOfInvalids: function() {
  221. return this.objectLength(this.invalid)
  222. },
  223. objectLength: function(a) {
  224. var b, c = 0;
  225. for (b in a) c++;
  226. return c
  227. },
  228. hideErrors: function() {
  229. this.hideThese(this.toHide)
  230. },
  231. hideThese: function(a) {
  232. a.not(this.containers).text(""), this.addWrapper(a).hide()
  233. },
  234. valid: function() {
  235. return 0 === this.size()
  236. },
  237. size: function() {
  238. return this.errorList.length
  239. },
  240. focusInvalid: function() {
  241. if (this.settings.focusInvalid) try {
  242. a(this.findLastActive() || this.errorList.length && this.errorList[0].element ||
  243. []).filter(":visible").focus().trigger("focusin")
  244. } catch (b) {}
  245. },
  246. findLastActive: function() {
  247. var b = this.lastActive;
  248. return b && 1 === a.grep(this.errorList, function(a) {
  249. return a.element.name === b.name
  250. }).length && b
  251. },
  252. elements: function() {
  253. var b = this,
  254. c = {};
  255. return a(this.currentForm).find("input, select, textarea").not(
  256. ":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(
  257. function() {
  258. // return !this.name && b.settings.debug && window.console && console.error(
  259. // "%o has no name assigned", this), this.name in c || !b.objectLength(
  260. // a(this).rules()) ? !1 : (c[this.name] = !0, !0)
  261. //相同name不校验问题
  262. return !this.name && b.settings.debug && window.console && console.error("%o has no name assigned", this),
  263. //this.name in c || !b.objectLength(a(this).rules()) ? !1 : (c[this.name] = !0, !0)//注释这行
  264. c[this.name] = !0, !0 //添加这行
  265. })
  266. },
  267. clean: function(b) {
  268. return a(b)[0]
  269. },
  270. errors: function() {
  271. var b = this.settings.errorClass.split(" ").join(".");
  272. return a(this.settings.errorElement + "." + b, this.errorContext)
  273. },
  274. reset: function() {
  275. this.successList = [], this.errorList = [], this.errorMap = {}, this.toShow = a([]),
  276. this.toHide = a([]), this.currentElements = a([])
  277. },
  278. prepareForm: function() {
  279. this.reset(), this.toHide = this.errors().add(this.containers)
  280. },
  281. prepareElement: function(a) {
  282. this.reset(), this.toHide = this.errorsFor(a)
  283. },
  284. elementValue: function(b) {
  285. var c, d = a(b),
  286. e = b.type;
  287. return "radio" === e || "checkbox" === e ? this.findByName(b.name).filter(":checked")
  288. .val() : "number" === e && "undefined" != typeof b.validity ? b.validity.badInput ?
  289. !1 : d.val() : (c = d.val(), "string" == typeof c ? c.replace(/\r/g, "") : c)
  290. },
  291. check: function(b) {
  292. b = this.validationTargetFor(this.clean(b));
  293. var c, d, e, f = a(b).rules(),
  294. g = a.map(f, function(a, b) {
  295. return b
  296. }).length,
  297. h = !1,
  298. i = this.elementValue(b);
  299. for (d in f) {
  300. e = {
  301. method: d,
  302. parameters: f[d]
  303. };
  304. try {
  305. if (c = a.validator.methods[d].call(this, i, b, e.parameters),
  306. "dependency-mismatch" === c && 1 === g) {
  307. h = !0;
  308. continue
  309. }
  310. if (h = !1, "pending" === c) return void(this.toHide = this.toHide.not(this
  311. .errorsFor(b)));
  312. if (!c) return this.formatAndAdd(b, e), !1
  313. } catch (j) {
  314. throw this.settings.debug && window.console && console.log(
  315. "Exception occurred when checking element " + b.id + ", check the '" + e
  316. .method + "' method.", j), j instanceof TypeError && (j.message +=
  317. ". Exception occurred when checking element " + b.id +
  318. ", check the '" + e.method + "' method."), j
  319. }
  320. }
  321. if (!h) return this.objectLength(f) && this.successList.push(b), !0
  322. },
  323. customDataMessage: function(b, c) {
  324. return a(b).data("msg" + c.charAt(0).toUpperCase() + c.substring(1).toLowerCase()) || a(
  325. b).data("msg")
  326. },
  327. customMessage: function(a, b) {
  328. var c = this.settings.messages[a];
  329. return c && (c.constructor === String ? c : c[b])
  330. },
  331. findDefined: function() {
  332. for (var a = 0; a < arguments.length; a++)
  333. if (void 0 !== arguments[a]) return arguments[a];
  334. return void 0
  335. },
  336. defaultMessage: function(b, c) {
  337. return this.findDefined(this.customMessage(b.name, c), this.customDataMessage(b, c), !
  338. this.settings.ignoreTitle && b.title || void 0, a.validator.messages[c],
  339. "<strong>Warning: No message defined for " + b.name + "</strong>")
  340. },
  341. formatAndAdd: function(b, c) {
  342. var d = this.defaultMessage(b, c.method),
  343. e = /\$?\{(\d+)\}/g;
  344. "function" == typeof d ? d = d.call(this, c.parameters, b) : e.test(d) && (d = a
  345. .validator.format(d.replace(e, "{$1}"), c.parameters)), this.errorList.push({
  346. message: d,
  347. element: b,
  348. method: c.method
  349. }), this.errorMap[b.name] = d, this.submitted[b.name] = d
  350. },
  351. addWrapper: function(a) {
  352. return this.settings.wrapper && (a = a.add(a.parent(this.settings.wrapper))), a
  353. },
  354. defaultShowErrors: function() {
  355. var a, b, c;
  356. for (a = 0; this.errorList[a]; a++) c = this.errorList[a], this.settings.highlight &&
  357. this.settings.highlight.call(this, c.element, this.settings.errorClass, this
  358. .settings.validClass), this.showLabel(c.element, c.message);
  359. if (this.errorList.length && (this.toShow = this.toShow.add(this.containers)), this
  360. .settings.success)
  361. for (a = 0; this.successList[a]; a++) this.showLabel(this.successList[a]);
  362. if (this.settings.unhighlight)
  363. for (a = 0, b = this.validElements(); b[a]; a++) this.settings.unhighlight.call(
  364. this, b[a], this.settings.errorClass, this.settings.validClass);
  365. this.toHide = this.toHide.not(this.toShow), this.hideErrors(), this.addWrapper(this
  366. .toShow).show()
  367. },
  368. validElements: function() {
  369. return this.currentElements.not(this.invalidElements())
  370. },
  371. invalidElements: function() {
  372. return a(this.errorList).map(function() {
  373. return this.element
  374. })
  375. },
  376. showLabel: function(b, c) {
  377. var d, e, f, g = this.errorsFor(b),
  378. h = this.idOrName(b),
  379. i = a(b).attr("aria-describedby");
  380. g.length ? (g.removeClass(this.settings.validClass).addClass(this.settings.errorClass),
  381. g.html(c)) : (g = a("<" + this.settings.errorElement + ">").attr("id", h +
  382. "-error").addClass(this.settings.errorClass).html(c || ""), d = g, this
  383. .settings.wrapper && (d = g.hide().show().wrap("<" + this.settings.wrapper +
  384. "/>").parent()), this.labelContainer.length ? this.labelContainer.append(
  385. d) : this.settings.errorPlacement ? this.settings.errorPlacement(d, a(b)) : d
  386. .insertAfter(b), g.is("label") ? g.attr("for", h) : 0 === g.parents(
  387. "label[for='" + h + "']").length && (f = g.attr("id").replace(
  388. /(:|\.|\[|\]|\$)/g, "\\$1"), i ? i.match(new RegExp("\\b" + f +
  389. "\\b")) || (i += " " + f) : i = f, a(b).attr("aria-describedby", i), e =
  390. this.groups[b.name], e && a.each(this.groups, function(b, c) {
  391. c === e && a("[name='" + b + "']", this.currentForm).attr(
  392. "aria-describedby", g.attr("id"))
  393. }))), !c && this.settings.success && (g.text(""), "string" == typeof this
  394. .settings.success ? g.addClass(this.settings.success) : this.settings.success(g,
  395. b)), this.toShow = this.toShow.add(g)
  396. },
  397. errorsFor: function(b) {
  398. var c = this.idOrName(b),
  399. d = a(b).attr("aria-describedby"),
  400. e = "label[for='" + c + "'], label[for='" + c + "'] *";
  401. return d && (e = e + ", #" + d.replace(/\s+/g, ", #")), this.errors().filter(e)
  402. },
  403. idOrName: function(a) {
  404. return this.groups[a.name] || (this.checkable(a) ? a.name : a.id || a.name)
  405. },
  406. validationTargetFor: function(b) {
  407. return this.checkable(b) && (b = this.findByName(b.name)), a(b).not(this.settings
  408. .ignore)[0]
  409. },
  410. checkable: function(a) {
  411. return /radio|checkbox/i.test(a.type)
  412. },
  413. findByName: function(b) {
  414. return a(this.currentForm).find("[name='" + b + "']")
  415. },
  416. getLength: function(b, c) {
  417. switch (c.nodeName.toLowerCase()) {
  418. case "select":
  419. return a("option:selected", c).length;
  420. case "input":
  421. if (this.checkable(c)) return this.findByName(c.name).filter(":checked").length
  422. }
  423. return b.length
  424. },
  425. depend: function(a, b) {
  426. return this.dependTypes[typeof a] ? this.dependTypes[typeof a](a, b) : !0
  427. },
  428. dependTypes: {
  429. "boolean": function(a) {
  430. return a
  431. },
  432. string: function(b, c) {
  433. return !!a(b, c.form).length
  434. },
  435. "function": function(a, b) {
  436. return a(b)
  437. }
  438. },
  439. optional: function(b) {
  440. var c = this.elementValue(b);
  441. return !a.validator.methods.required.call(this, c, b) && "dependency-mismatch"
  442. },
  443. startRequest: function(a) {
  444. this.pending[a.name] || (this.pendingRequest++, this.pending[a.name] = !0)
  445. },
  446. stopRequest: function(b, c) {
  447. this.pendingRequest--, this.pendingRequest < 0 && (this.pendingRequest = 0), delete this
  448. .pending[b.name], c && 0 === this.pendingRequest && this.formSubmitted && this
  449. .form() ? (a(this.currentForm).submit(), this.formSubmitted = !1) : !c && 0 === this
  450. .pendingRequest && this.formSubmitted && (a(this.currentForm).triggerHandler(
  451. "invalid-form", [this]), this.formSubmitted = !1)
  452. },
  453. previousValue: function(b) {
  454. return a.data(b, "previousValue") || a.data(b, "previousValue", {
  455. old: null,
  456. valid: !0,
  457. message: this.defaultMessage(b, "remote")
  458. })
  459. },
  460. destroy: function() {
  461. this.resetForm(), a(this.currentForm).off(".validate").removeData("validator")
  462. }
  463. },
  464. classRuleSettings: {
  465. required: {
  466. required: !0
  467. },
  468. email: {
  469. email: !0
  470. },
  471. url: {
  472. url: !0
  473. },
  474. date: {
  475. date: !0
  476. },
  477. dateISO: {
  478. dateISO: !0
  479. },
  480. number: {
  481. number: !0
  482. },
  483. digits: {
  484. digits: !0
  485. },
  486. creditcard: {
  487. creditcard: !0
  488. }
  489. },
  490. addClassRules: function(b, c) {
  491. b.constructor === String ? this.classRuleSettings[b] = c : a.extend(this.classRuleSettings,
  492. b)
  493. },
  494. classRules: function(b) {
  495. var c = {},
  496. d = a(b).attr("class");
  497. return d && a.each(d.split(" "), function() {
  498. this in a.validator.classRuleSettings && a.extend(c, a.validator
  499. .classRuleSettings[this])
  500. }), c
  501. },
  502. normalizeAttributeRule: function(a, b, c, d) {
  503. /min|max/.test(c) && (null === b || /number|range|text/.test(b)) && (d = Number(d), isNaN(
  504. d) && (d = void 0)), d || 0 === d ? a[c] = d : b === c && "range" !== b && (a[c] = !
  505. 0)
  506. },
  507. attributeRules: function(b) {
  508. var c, d, e = {},
  509. f = a(b),
  510. g = b.getAttribute("type");
  511. for (c in a.validator.methods) "required" === c ? (d = b.getAttribute(c), "" === d && (d = !
  512. 0), d = !!d) : d = f.attr(c), this.normalizeAttributeRule(e, g, c, d);
  513. return e.maxlength && /-1|2147483647|524288/.test(e.maxlength) && delete e.maxlength, e
  514. },
  515. dataRules: function(b) {
  516. var c, d, e = {},
  517. f = a(b),
  518. g = b.getAttribute("type");
  519. for (c in a.validator.methods) d = f.data("rule" + c.charAt(0).toUpperCase() + c.substring(
  520. 1).toLowerCase()), this.normalizeAttributeRule(e, g, c, d);
  521. return e
  522. },
  523. staticRules: function(b) {
  524. var c = {},
  525. d = a.data(b.form, "validator");
  526. return d.settings.rules && (c = a.validator.normalizeRule(d.settings.rules[b.name]) || {}),
  527. c
  528. },
  529. normalizeRules: function(b, c) {
  530. return a.each(b, function(d, e) {
  531. if (e === !1) return void delete b[d];
  532. if (e.param || e.depends) {
  533. var f = !0;
  534. switch (typeof e.depends) {
  535. case "string":
  536. f = !!a(e.depends, c.form).length;
  537. break;
  538. case "function":
  539. f = e.depends.call(c, c)
  540. }
  541. f ? b[d] = void 0 !== e.param ? e.param : !0 : delete b[d]
  542. }
  543. }), a.each(b, function(d, e) {
  544. b[d] = a.isFunction(e) ? e(c) : e
  545. }), a.each(["minlength", "maxlength"], function() {
  546. b[this] && (b[this] = Number(b[this]))
  547. }), a.each(["rangelength", "range"], function() {
  548. var c;
  549. b[this] && (a.isArray(b[this]) ? b[this] = [Number(b[this][0]), Number(b[this][
  550. 1])] : "string" == typeof b[this] && (c = b[this].replace(/[\[\]]/g,
  551. "").split(/[\s,]+/), b[this] = [Number(c[0]), Number(c[1])]))
  552. }), a.validator.autoCreateRanges && (null != b.min && null != b.max && (b.range = [b
  553. .min, b.max
  554. ], delete b.min, delete b.max), null != b.minlength && null != b.maxlength && (b
  555. .rangelength = [b.minlength, b.maxlength], delete b.minlength, delete b
  556. .maxlength)), b
  557. },
  558. normalizeRule: function(b) {
  559. if ("string" == typeof b) {
  560. var c = {};
  561. a.each(b.split(/\s/), function() {
  562. c[this] = !0
  563. }), b = c
  564. }
  565. return b
  566. },
  567. addMethod: function(b, c, d) {
  568. a.validator.methods[b] = c, a.validator.messages[b] = void 0 !== d ? d : a.validator
  569. .messages[b], c.length < 3 && a.validator.addClassRules(b, a.validator.normalizeRule(b))
  570. },
  571. methods: {
  572. required: function(b, c, d) {
  573. if (!this.depend(d, c)) return "dependency-mismatch";
  574. if ("select" === c.nodeName.toLowerCase()) {
  575. var e = a(c).val();
  576. return e && e.length > 0
  577. }
  578. return this.checkable(c) ? this.getLength(b, c) > 0 : b.length > 0
  579. },
  580. email: function(a, b) {
  581. return this.optional(b) ||
  582. /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
  583. .test(a)
  584. },
  585. url: function(a, b) {
  586. return this.optional(b) ||
  587. /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i
  588. .test(a)
  589. },
  590. date: function(a, b) {
  591. return this.optional(b) || !/Invalid|NaN/.test(new Date(a).toString())
  592. },
  593. dateISO: function(a, b) {
  594. return this.optional(b) ||
  595. /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(a)
  596. },
  597. number: function(a, b) {
  598. return this.optional(b) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(a)
  599. },
  600. digits: function(a, b) {
  601. return this.optional(b) || /^\d+$/.test(a)
  602. },
  603. creditcard: function(a, b) {
  604. if (this.optional(b)) return "dependency-mismatch";
  605. if (/[^0-9 \-]+/.test(a)) return !1;
  606. var c, d, e = 0,
  607. f = 0,
  608. g = !1;
  609. if (a = a.replace(/\D/g, ""), a.length < 13 || a.length > 19) return !1;
  610. for (c = a.length - 1; c >= 0; c--) d = a.charAt(c), f = parseInt(d, 10), g && (f *=
  611. 2) > 9 && (f -= 9), e += f, g = !g;
  612. return e % 10 === 0
  613. },
  614. minlength: function(b, c, d) {
  615. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  616. return this.optional(c) || e >= d
  617. },
  618. maxlength: function(b, c, d) {
  619. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  620. return this.optional(c) || d >= e
  621. },
  622. rangelength: function(b, c, d) {
  623. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  624. return this.optional(c) || e >= d[0] && e <= d[1]
  625. },
  626. min: function(a, b, c) {
  627. return this.optional(b) || a >= c
  628. },
  629. max: function(a, b, c) {
  630. return this.optional(b) || c >= a
  631. },
  632. range: function(a, b, c) {
  633. return this.optional(b) || a >= c[0] && a <= c[1]
  634. },
  635. equalTo: function(b, c, d) {
  636. var e = a(d);
  637. return this.settings.onfocusout && e.off(".validate-equalTo").on(
  638. "blur.validate-equalTo",
  639. function() {
  640. a(c).valid()
  641. }), b === e.val()
  642. },
  643. remote: function(b, c, d) {
  644. if (this.optional(c)) return "dependency-mismatch";
  645. var e, f, g = this.previousValue(c);
  646. return this.settings.messages[c.name] || (this.settings.messages[c.name] = {}), g
  647. .originalMessage = this.settings.messages[c.name].remote, this.settings.messages[c
  648. .name].remote = g.message, d = "string" == typeof d && {
  649. url: d
  650. } || d, g.old === b ? g.valid : (g.old = b, e = this, this.startRequest(c), f = {},
  651. f[c.name] = b, a.ajax(a.extend(!0, {
  652. mode: "abort",
  653. port: "validate" + c.name,
  654. dataType: "json",
  655. data: f,
  656. context: e.currentForm,
  657. success: function(d) {
  658. var f, h, i, j = d === !0 || "true" === d;
  659. e.settings.messages[c.name].remote = g.originalMessage, j ?
  660. (i = e.formSubmitted, e.prepareElement(c), e
  661. .formSubmitted = i, e.successList.push(c), delete e
  662. .invalid[c.name], e.showErrors()) : (f = {}, h =
  663. d || e.defaultMessage(c, "remote"), f[c.name] = g
  664. .message = a.isFunction(h) ? h(b) : h, e.invalid[c
  665. .name] = !0, e.showErrors(f)), g.valid = j, e
  666. .stopRequest(c, j)
  667. }
  668. }, d)), "pending")
  669. }
  670. }
  671. });
  672. var b, c = {};
  673. a.ajaxPrefilter ? a.ajaxPrefilter(function(a, b, d) {
  674. var e = a.port;
  675. "abort" === a.mode && (c[e] && c[e].abort(), c[e] = d)
  676. }) : (b = a.ajax, a.ajax = function(d) {
  677. var e = ("mode" in d ? d : a.ajaxSettings).mode,
  678. f = ("port" in d ? d : a.ajaxSettings).port;
  679. return "abort" === e ? (c[f] && c[f].abort(), c[f] = b.apply(this, arguments), c[f]) : b.apply(this,
  680. arguments)
  681. })
  682. });