jquery.validate.min.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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("Nothing selected, can't validate, returning nothing."));
  10. var c = a.data(this[0], "validator");
  11. return c ? c : (this.attr("novalidate", "novalidate"), c = new a.validator(b, this[0]), a.data(this[0], "validator", c), c.settings.onsubmit && (this.on("click.validate", ":submit", function (b) {
  12. c.settings.submitHandler && (c.submitButton = b.target), a(this).hasClass("cancel") && (c.cancelSubmit = !0), void 0 !== a(this).attr("formnovalidate") && (c.cancelSubmit = !0)
  13. }), this.on("submit.validate", function (b) {
  14. function d() {
  15. var d, e;
  16. return c.settings.submitHandler ? (c.submitButton && (d = a("<input type='hidden'/>").attr("name", c.submitButton.name).val(a(c.submitButton).val()).appendTo(c.currentForm)), e = c.settings.submitHandler.call(c, c.currentForm, b), c.submitButton && d.remove(), void 0 !== e ? e : !1) : !0
  17. }
  18. return c.settings.debug && b.preventDefault(), c.cancelSubmit ? (c.cancelSubmit = !1, d()) : c.form() ? c.pendingRequest ? (c.formSubmitted = !0, !1) : d() : (c.focusInvalid(), !1)
  19. })), c)
  20. }, valid: function () {
  21. var b, c, d;
  22. return a(this[0]).is("form") ? b = this.validate().form() : (d = [], b = !0, c = a(this[0].form).validate(), this.each(function () {
  23. b = c.element(this) && b, d = d.concat(c.errorList)
  24. }), c.errorList = d), b
  25. }, rules: function (b, c) {
  26. var d, e, f, g, h, i, j = this[0];
  27. if (b) switch (d = a.data(j.form, "validator").settings, e = d.rules, f = a.validator.staticRules(j), b) {
  28. case"add":
  29. a.extend(f, a.validator.normalizeRule(c)), delete f.messages, e[j.name] = f, c.messages && (d.messages[j.name] = a.extend(d.messages[j.name], c.messages));
  30. break;
  31. case"remove":
  32. return c ? (i = {}, a.each(c.split(/\s/), function (b, c) {
  33. i[c] = f[c], delete f[c], "required" === c && a(j).removeAttr("aria-required")
  34. }), i) : (delete e[j.name], f)
  35. }
  36. return g = a.validator.normalizeRules(a.extend({}, a.validator.classRules(j), a.validator.attributeRules(j), a.validator.dataRules(j), a.validator.staticRules(j)), j), g.required && (h = g.required, delete g.required, g = a.extend({required: h}, g), a(j).attr("aria-required", "true")), g.remote && (h = g.remote, delete g.remote, g = a.extend(g, {remote: h})), g
  37. }
  38. }), a.extend(a.expr[":"], {
  39. blank: function (b) {
  40. return !a.trim("" + a(b).val())
  41. }, filled: function (b) {
  42. return !!a.trim("" + a(b).val())
  43. }, unchecked: function (b) {
  44. return !a(b).prop("checked")
  45. }
  46. }), a.validator = function (b, c) {
  47. this.settings = a.extend(!0, {}, a.validator.defaults, b), this.currentForm = c, this.init()
  48. }, a.validator.format = function (b, c) {
  49. return 1 === arguments.length ? function () {
  50. var c = a.makeArray(arguments);
  51. return c.unshift(b), a.validator.format.apply(this, c)
  52. } : (arguments.length > 2 && c.constructor !== Array && (c = a.makeArray(arguments).slice(1)), c.constructor !== Array && (c = [c]), a.each(c, function (a, c) {
  53. b = b.replace(new RegExp("\\{" + a + "\\}", "g"), function () {
  54. return c
  55. })
  56. }), b)
  57. }, a.extend(a.validator, {
  58. defaults: {
  59. messages: {},
  60. groups: {},
  61. rules: {},
  62. errorClass: "error",
  63. validClass: "valid",
  64. errorElement: "label",
  65. focusCleanup: !1,
  66. focusInvalid: !0,
  67. errorContainer: a([]),
  68. errorLabelContainer: a([]),
  69. onsubmit: !0,
  70. ignore: ":hidden",
  71. ignoreTitle: !1,
  72. onfocusin: function (a) {
  73. this.lastActive = a, this.settings.focusCleanup && (this.settings.unhighlight && this.settings.unhighlight.call(this, a, this.settings.errorClass, this.settings.validClass), this.hideThese(this.errorsFor(a)))
  74. },
  75. onfocusout: function (a) {
  76. this.checkable(a) || !(a.name in this.submitted) && this.optional(a) || this.element(a)
  77. },
  78. onkeyup: function (b, c) {
  79. var d = [16, 17, 18, 20, 35, 36, 37, 38, 39, 40, 45, 144, 225];
  80. 9 === c.which && "" === this.elementValue(b) || -1 !== a.inArray(c.keyCode, d) || (b.name in this.submitted || b === this.lastElement) && this.element(b)
  81. },
  82. onclick: function (a) {
  83. a.name in this.submitted ? this.element(a) : a.parentNode.name in this.submitted && this.element(a.parentNode)
  84. },
  85. highlight: function (b, c, d) {
  86. "radio" === b.type ? this.findByName(b.name).addClass(c).removeClass(d) : a(b).addClass(c).removeClass(d)
  87. },
  88. unhighlight: function (b, c, d) {
  89. "radio" === b.type ? this.findByName(b.name).removeClass(c).addClass(d) : a(b).removeClass(c).addClass(d)
  90. }
  91. },
  92. setDefaults: function (b) {
  93. a.extend(a.validator.defaults, b)
  94. },
  95. messages: {
  96. required: "This field is required.",
  97. remote: "Please fix this field.",
  98. email: "Please enter a valid email address.",
  99. url: "Please enter a valid URL.",
  100. date: "Please enter a valid date.",
  101. dateISO: "Please enter a valid date ( ISO ).",
  102. number: "Please enter a valid number.",
  103. digits: "Please enter only digits.",
  104. creditcard: "Please enter a valid credit card number.",
  105. equalTo: "Please enter the same value again.",
  106. maxlength: a.validator.format("Please enter no more than {0} characters."),
  107. minlength: a.validator.format("Please enter at least {0} characters."),
  108. rangelength: a.validator.format("Please enter a value between {0} and {1} characters long."),
  109. range: a.validator.format("Please enter a value between {0} and {1}."),
  110. max: a.validator.format("Please enter a value less than or equal to {0}."),
  111. min: a.validator.format("Please enter a value greater than or equal to {0}.")
  112. },
  113. autoCreateRanges: !1,
  114. prototype: {
  115. init: function () {
  116. function b(b) {
  117. var c = a.data(this.form, "validator"), d = "on" + b.type.replace(/^validate/, ""), e = c.settings;
  118. e[d] && !a(this).is(e.ignore) && e[d].call(c, this, b)
  119. }
  120. this.labelContainer = a(this.settings.errorLabelContainer), this.errorContext = this.labelContainer.length && this.labelContainer || a(this.currentForm), this.containers = a(this.settings.errorContainer).add(this.settings.errorLabelContainer), this.submitted = {}, this.valueCache = {}, this.pendingRequest = 0, this.pending = {}, this.invalid = {}, this.reset();
  121. var c, d = this.groups = {};
  122. a.each(this.settings.groups, function (b, c) {
  123. "string" == typeof c && (c = c.split(/\s/)), a.each(c, function (a, c) {
  124. d[c] = b
  125. })
  126. }), c = this.settings.rules, a.each(c, function (b, d) {
  127. c[b] = a.validator.normalizeRule(d)
  128. }), a(this.currentForm).on("focusin.validate focusout.validate keyup.validate", ":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']", b).on("click.validate", "select, option, [type='radio'], [type='checkbox']", b), this.settings.invalidHandler && a(this.currentForm).on("invalid-form.validate", this.settings.invalidHandler), a(this.currentForm).find("[required], [data-rule-required], .required").attr("aria-required", "true")
  129. }, form: function () {
  130. return this.checkForm(), a.extend(this.submitted, this.errorMap), this.invalid = a.extend({}, this.errorMap), this.valid() || a(this.currentForm).triggerHandler("invalid-form", [this]), this.showErrors(), this.valid()
  131. }, checkForm: function () {
  132. this.prepareForm();
  133. for (var a = 0, b = this.currentElements = this.elements(); b[a]; a++) this.check(b[a]);
  134. return this.valid()
  135. }, element: function (b) {
  136. var c = this.clean(b), d = this.validationTargetFor(c), e = !0;
  137. return this.lastElement = d, void 0 === d ? delete this.invalid[c.name] : (this.prepareElement(d), this.currentElements = a(d), e = this.check(d) !== !1, e ? delete this.invalid[d.name] : this.invalid[d.name] = !0), a(b).attr("aria-invalid", !e), this.numberOfInvalids() || (this.toHide = this.toHide.add(this.containers)), this.showErrors(), e
  138. }, showErrors: function (b) {
  139. if (b) {
  140. a.extend(this.errorMap, b), this.errorList = [];
  141. for (var c in b) this.errorList.push({message: b[c], element: this.findByName(c)[0]});
  142. this.successList = a.grep(this.successList, function (a) {
  143. return !(a.name in b)
  144. })
  145. }
  146. this.settings.showErrors ? this.settings.showErrors.call(this, this.errorMap, this.errorList) : this.defaultShowErrors()
  147. }, resetForm: function () {
  148. a.fn.resetForm && a(this.currentForm).resetForm(), this.submitted = {}, this.lastElement = null, this.prepareForm(), this.hideErrors();
  149. var b, c = this.elements().removeData("previousValue").removeAttr("aria-invalid");
  150. if (this.settings.unhighlight) for (b = 0; c[b]; b++) this.settings.unhighlight.call(this, c[b], this.settings.errorClass, ""); else c.removeClass(this.settings.errorClass)
  151. }, numberOfInvalids: function () {
  152. return this.objectLength(this.invalid)
  153. }, objectLength: function (a) {
  154. var b, c = 0;
  155. for (b in a) c++;
  156. return c
  157. }, hideErrors: function () {
  158. this.hideThese(this.toHide)
  159. }, hideThese: function (a) {
  160. a.not(this.containers).text(""), this.addWrapper(a).hide()
  161. }, valid: function () {
  162. return 0 === this.size()
  163. }, size: function () {
  164. return this.errorList.length
  165. }, focusInvalid: function () {
  166. if (this.settings.focusInvalid) try {
  167. a(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus().trigger("focusin")
  168. } catch (b) {
  169. }
  170. }, findLastActive: function () {
  171. var b = this.lastActive;
  172. return b && 1 === a.grep(this.errorList, function (a) {
  173. return a.element.name === b.name
  174. }).length && b
  175. }, elements: function () {
  176. var b = this, c = {};
  177. return a(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(function () {
  178. return !this.name && b.settings.debug && window.console && console.error("%o has no name assigned", this), this.name in c || !b.objectLength(a(this).rules()) ? !1 : (c[this.name] = !0, !0)
  179. })
  180. }, clean: function (b) {
  181. return a(b)[0]
  182. }, errors: function () {
  183. var b = this.settings.errorClass.split(" ").join(".");
  184. return a(this.settings.errorElement + "." + b, this.errorContext)
  185. }, reset: function () {
  186. this.successList = [], this.errorList = [], this.errorMap = {}, this.toShow = a([]), this.toHide = a([]), this.currentElements = a([])
  187. }, prepareForm: function () {
  188. this.reset(), this.toHide = this.errors().add(this.containers)
  189. }, prepareElement: function (a) {
  190. this.reset(), this.toHide = this.errorsFor(a)
  191. }, elementValue: function (b) {
  192. var c, d = a(b), e = b.type;
  193. return "radio" === e || "checkbox" === e ? this.findByName(b.name).filter(":checked").val() : "number" === e && "undefined" != typeof b.validity ? b.validity.badInput ? !1 : d.val() : (c = d.val(), "string" == typeof c ? c.replace(/\r/g, "") : c)
  194. }, check: function (b) {
  195. b = this.validationTargetFor(this.clean(b));
  196. var c, d, e, f = a(b).rules(), g = a.map(f, function (a, b) {
  197. return b
  198. }).length, h = !1, i = this.elementValue(b);
  199. for (d in f) {
  200. e = {method: d, parameters: f[d]};
  201. try {
  202. if (c = a.validator.methods[d].call(this, i, b, e.parameters), "dependency-mismatch" === c && 1 === g) {
  203. h = !0;
  204. continue
  205. }
  206. if (h = !1, "pending" === c) return void(this.toHide = this.toHide.not(this.errorsFor(b)));
  207. if (!c) return this.formatAndAdd(b, e), !1
  208. } catch (j) {
  209. throw this.settings.debug && window.console && console.log("Exception occurred when checking element " + b.id + ", check the '" + e.method + "' method.", j), j instanceof TypeError && (j.message += ". Exception occurred when checking element " + b.id + ", check the '" + e.method + "' method."), j
  210. }
  211. }
  212. if (!h) return this.objectLength(f) && this.successList.push(b), !0
  213. }, customDataMessage: function (b, c) {
  214. return a(b).data("msg" + c.charAt(0).toUpperCase() + c.substring(1).toLowerCase()) || a(b).data("msg")
  215. }, customMessage: function (a, b) {
  216. var c = this.settings.messages[a];
  217. return c && (c.constructor === String ? c : c[b])
  218. }, findDefined: function () {
  219. for (var a = 0; a < arguments.length; a++) if (void 0 !== arguments[a]) return arguments[a];
  220. return void 0
  221. }, defaultMessage: function (b, c) {
  222. return this.findDefined(this.customMessage(b.name, c), this.customDataMessage(b, c), !this.settings.ignoreTitle && b.title || void 0, a.validator.messages[c], "<strong>Warning: No message defined for " + b.name + "</strong>")
  223. }, formatAndAdd: function (b, c) {
  224. var d = this.defaultMessage(b, c.method), e = /\$?\{(\d+)\}/g;
  225. "function" == typeof d ? d = d.call(this, c.parameters, b) : e.test(d) && (d = a.validator.format(d.replace(e, "{$1}"), c.parameters)), this.errorList.push({
  226. message: d,
  227. element: b,
  228. method: c.method
  229. }), this.errorMap[b.name] = d, this.submitted[b.name] = d
  230. }, addWrapper: function (a) {
  231. return this.settings.wrapper && (a = a.add(a.parent(this.settings.wrapper))), a
  232. }, defaultShowErrors: function () {
  233. var a, b, c;
  234. for (a = 0; this.errorList[a]; a++) c = this.errorList[a], this.settings.highlight && this.settings.highlight.call(this, c.element, this.settings.errorClass, this.settings.validClass), this.showLabel(c.element, c.message);
  235. if (this.errorList.length && (this.toShow = this.toShow.add(this.containers)), this.settings.success) for (a = 0; this.successList[a]; a++) this.showLabel(this.successList[a]);
  236. if (this.settings.unhighlight) for (a = 0, b = this.validElements(); b[a]; a++) this.settings.unhighlight.call(this, b[a], this.settings.errorClass, this.settings.validClass);
  237. this.toHide = this.toHide.not(this.toShow), this.hideErrors(), this.addWrapper(this.toShow).show()
  238. }, validElements: function () {
  239. return this.currentElements.not(this.invalidElements())
  240. }, invalidElements: function () {
  241. return a(this.errorList).map(function () {
  242. return this.element
  243. })
  244. }, showLabel: function (b, c) {
  245. var d, e, f, g = this.errorsFor(b), h = this.idOrName(b), i = a(b).attr("aria-describedby");
  246. g.length ? (g.removeClass(this.settings.validClass).addClass(this.settings.errorClass), g.html(c)) : (g = a("<" + this.settings.errorElement + ">").attr("id", h + "-error").addClass(this.settings.errorClass).html(c || ""), d = g, this.settings.wrapper && (d = g.hide().show().wrap("<" + this.settings.wrapper + "/>").parent()), this.labelContainer.length ? this.labelContainer.append(d) : this.settings.errorPlacement ? this.settings.errorPlacement(d, a(b)) : d.insertAfter(b), g.is("label") ? g.attr("for", h) : 0 === g.parents("label[for='" + h + "']").length && (f = g.attr("id").replace(/(:|\.|\[|\]|\$)/g, "\\$1"), i ? i.match(new RegExp("\\b" + f + "\\b")) || (i += " " + f) : i = f, a(b).attr("aria-describedby", i), e = this.groups[b.name], e && a.each(this.groups, function (b, c) {
  247. c === e && a("[name='" + b + "']", this.currentForm).attr("aria-describedby", g.attr("id"))
  248. }))), !c && this.settings.success && (g.text(""), "string" == typeof this.settings.success ? g.addClass(this.settings.success) : this.settings.success(g, b)), this.toShow = this.toShow.add(g)
  249. }, errorsFor: function (b) {
  250. var c = this.idOrName(b), d = a(b).attr("aria-describedby"),
  251. e = "label[for='" + c + "'], label[for='" + c + "'] *";
  252. return d && (e = e + ", #" + d.replace(/\s+/g, ", #")), this.errors().filter(e)
  253. }, idOrName: function (a) {
  254. return this.groups[a.name] || (this.checkable(a) ? a.name : a.id || a.name)
  255. }, validationTargetFor: function (b) {
  256. return this.checkable(b) && (b = this.findByName(b.name)), a(b).not(this.settings.ignore)[0]
  257. }, checkable: function (a) {
  258. return /radio|checkbox/i.test(a.type)
  259. }, findByName: function (b) {
  260. return a(this.currentForm).find("[name='" + b + "']")
  261. }, getLength: function (b, c) {
  262. switch (c.nodeName.toLowerCase()) {
  263. case"select":
  264. return a("option:selected", c).length;
  265. case"input":
  266. if (this.checkable(c)) return this.findByName(c.name).filter(":checked").length
  267. }
  268. return b.length
  269. }, depend: function (a, b) {
  270. return this.dependTypes[typeof a] ? this.dependTypes[typeof a](a, b) : !0
  271. }, dependTypes: {
  272. "boolean": function (a) {
  273. return a
  274. }, string: function (b, c) {
  275. return !!a(b, c.form).length
  276. }, "function": function (a, b) {
  277. return a(b)
  278. }
  279. }, optional: function (b) {
  280. var c = this.elementValue(b);
  281. return !a.validator.methods.required.call(this, c, b) && "dependency-mismatch"
  282. }, startRequest: function (a) {
  283. this.pending[a.name] || (this.pendingRequest++, this.pending[a.name] = !0)
  284. }, stopRequest: function (b, c) {
  285. this.pendingRequest--, this.pendingRequest < 0 && (this.pendingRequest = 0), delete this.pending[b.name], c && 0 === this.pendingRequest && this.formSubmitted && this.form() ? (a(this.currentForm).submit(), this.formSubmitted = !1) : !c && 0 === this.pendingRequest && this.formSubmitted && (a(this.currentForm).triggerHandler("invalid-form", [this]), this.formSubmitted = !1)
  286. }, previousValue: function (b) {
  287. return a.data(b, "previousValue") || a.data(b, "previousValue", {
  288. old: null,
  289. valid: !0,
  290. message: this.defaultMessage(b, "remote")
  291. })
  292. }, destroy: function () {
  293. this.resetForm(), a(this.currentForm).off(".validate").removeData("validator")
  294. }
  295. },
  296. classRuleSettings: {
  297. required: {required: !0},
  298. email: {email: !0},
  299. url: {url: !0},
  300. date: {date: !0},
  301. dateISO: {dateISO: !0},
  302. number: {number: !0},
  303. digits: {digits: !0},
  304. creditcard: {creditcard: !0}
  305. },
  306. addClassRules: function (b, c) {
  307. b.constructor === String ? this.classRuleSettings[b] = c : a.extend(this.classRuleSettings, b)
  308. },
  309. classRules: function (b) {
  310. var c = {}, d = a(b).attr("class");
  311. return d && a.each(d.split(" "), function () {
  312. this in a.validator.classRuleSettings && a.extend(c, a.validator.classRuleSettings[this])
  313. }), c
  314. },
  315. normalizeAttributeRule: function (a, b, c, d) {
  316. /min|max/.test(c) && (null === b || /number|range|text/.test(b)) && (d = Number(d), isNaN(d) && (d = void 0)), d || 0 === d ? a[c] = d : b === c && "range" !== b && (a[c] = !0)
  317. },
  318. attributeRules: function (b) {
  319. var c, d, e = {}, f = a(b), g = b.getAttribute("type");
  320. for (c in a.validator.methods) "required" === c ? (d = b.getAttribute(c), "" === d && (d = !0), d = !!d) : d = f.attr(c), this.normalizeAttributeRule(e, g, c, d);
  321. return e.maxlength && /-1|2147483647|524288/.test(e.maxlength) && delete e.maxlength, e
  322. },
  323. dataRules: function (b) {
  324. var c, d, e = {}, f = a(b), g = b.getAttribute("type");
  325. for (c in a.validator.methods) d = f.data("rule" + c.charAt(0).toUpperCase() + c.substring(1).toLowerCase()), this.normalizeAttributeRule(e, g, c, d);
  326. return e
  327. },
  328. staticRules: function (b) {
  329. var c = {}, d = a.data(b.form, "validator");
  330. return d.settings.rules && (c = a.validator.normalizeRule(d.settings.rules[b.name]) || {}), c
  331. },
  332. normalizeRules: function (b, c) {
  333. return a.each(b, function (d, e) {
  334. if (e === !1) return void delete b[d];
  335. if (e.param || e.depends) {
  336. var f = !0;
  337. switch (typeof e.depends) {
  338. case"string":
  339. f = !!a(e.depends, c.form).length;
  340. break;
  341. case"function":
  342. f = e.depends.call(c, c)
  343. }
  344. f ? b[d] = void 0 !== e.param ? e.param : !0 : delete b[d]
  345. }
  346. }), a.each(b, function (d, e) {
  347. b[d] = a.isFunction(e) ? e(c) : e
  348. }), a.each(["minlength", "maxlength"], function () {
  349. b[this] && (b[this] = Number(b[this]))
  350. }), a.each(["rangelength", "range"], function () {
  351. var c;
  352. b[this] && (a.isArray(b[this]) ? b[this] = [Number(b[this][0]), Number(b[this][1])] : "string" == typeof b[this] && (c = b[this].replace(/[\[\]]/g, "").split(/[\s,]+/), b[this] = [Number(c[0]), Number(c[1])]))
  353. }), a.validator.autoCreateRanges && (null != b.min && null != b.max && (b.range = [b.min, b.max], delete b.min, delete b.max), null != b.minlength && null != b.maxlength && (b.rangelength = [b.minlength, b.maxlength], delete b.minlength, delete b.maxlength)), b
  354. },
  355. normalizeRule: function (b) {
  356. if ("string" == typeof b) {
  357. var c = {};
  358. a.each(b.split(/\s/), function () {
  359. c[this] = !0
  360. }), b = c
  361. }
  362. return b
  363. },
  364. addMethod: function (b, c, d) {
  365. a.validator.methods[b] = c, a.validator.messages[b] = void 0 !== d ? d : a.validator.messages[b], c.length < 3 && a.validator.addClassRules(b, a.validator.normalizeRule(b))
  366. },
  367. methods: {
  368. required: function (b, c, d) {
  369. if (!this.depend(d, c)) return "dependency-mismatch";
  370. if ("select" === c.nodeName.toLowerCase()) {
  371. var e = a(c).val();
  372. return e && e.length > 0
  373. }
  374. return this.checkable(c) ? this.getLength(b, c) > 0 : b.length > 0
  375. }, email: function (a, b) {
  376. return this.optional(b) || /^[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])?)*$/.test(a)
  377. }, url: function (a, b) {
  378. return this.optional(b) || /^(?:(?:(?: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.test(a)
  379. }, date: function (a, b) {
  380. return this.optional(b) || !/Invalid|NaN/.test(new Date(a).toString())
  381. }, dateISO: function (a, b) {
  382. return this.optional(b) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(a)
  383. }, number: function (a, b) {
  384. return this.optional(b) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(a)
  385. }, digits: function (a, b) {
  386. return this.optional(b) || /^\d+$/.test(a)
  387. }, creditcard: function (a, b) {
  388. if (this.optional(b)) return "dependency-mismatch";
  389. if (/[^0-9 \-]+/.test(a)) return !1;
  390. var c, d, e = 0, f = 0, g = !1;
  391. if (a = a.replace(/\D/g, ""), a.length < 13 || a.length > 19) return !1;
  392. for (c = a.length - 1; c >= 0; c--) d = a.charAt(c), f = parseInt(d, 10), g && (f *= 2) > 9 && (f -= 9), e += f, g = !g;
  393. return e % 10 === 0
  394. }, minlength: function (b, c, d) {
  395. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  396. return this.optional(c) || e >= d
  397. }, maxlength: function (b, c, d) {
  398. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  399. return this.optional(c) || d >= e
  400. }, rangelength: function (b, c, d) {
  401. var e = a.isArray(b) ? b.length : this.getLength(b, c);
  402. return this.optional(c) || e >= d[0] && e <= d[1]
  403. }, min: function (a, b, c) {
  404. return this.optional(b) || a >= c
  405. }, max: function (a, b, c) {
  406. return this.optional(b) || c >= a
  407. }, range: function (a, b, c) {
  408. return this.optional(b) || a >= c[0] && a <= c[1]
  409. }, equalTo: function (b, c, d) {
  410. var e = a(d);
  411. return this.settings.onfocusout && e.off(".validate-equalTo").on("blur.validate-equalTo", function () {
  412. a(c).valid()
  413. }), b === e.val()
  414. }, remote: function (b, c, d) {
  415. if (this.optional(c)) return "dependency-mismatch";
  416. var e, f, g = this.previousValue(c);
  417. return this.settings.messages[c.name] || (this.settings.messages[c.name] = {}), g.originalMessage = this.settings.messages[c.name].remote, this.settings.messages[c.name].remote = g.message, d = "string" == typeof d && {url: d} || d, g.old === b ? g.valid : (g.old = b, e = this, this.startRequest(c), f = {}, f[c.name] = b, a.ajax(a.extend(!0, {
  418. mode: "abort",
  419. port: "validate" + c.name,
  420. dataType: "json",
  421. data: f,
  422. context: e.currentForm,
  423. success: function (d) {
  424. var f, h, i, j = d === !0 || "true" === d;
  425. e.settings.messages[c.name].remote = g.originalMessage, j ? (i = e.formSubmitted, e.prepareElement(c), e.formSubmitted = i, e.successList.push(c), delete e.invalid[c.name], e.showErrors()) : (f = {}, h = d || e.defaultMessage(c, "remote"), f[c.name] = g.message = a.isFunction(h) ? h(b) : h, e.invalid[c.name] = !0, e.showErrors(f)), g.valid = j, e.stopRequest(c, j)
  426. }
  427. }, d)), "pending")
  428. }
  429. }
  430. });
  431. var b, c = {};
  432. a.ajaxPrefilter ? a.ajaxPrefilter(function (a, b, d) {
  433. var e = a.port;
  434. "abort" === a.mode && (c[e] && c[e].abort(), c[e] = d)
  435. }) : (b = a.ajax, a.ajax = function (d) {
  436. var e = ("mode" in d ? d : a.ajaxSettings).mode, f = ("port" in d ? d : a.ajaxSettings).port;
  437. return "abort" === e ? (c[f] && c[f].abort(), c[f] = b.apply(this, arguments), c[f]) : b.apply(this, arguments)
  438. })
  439. });