jquery.validation.min.js 34 KB

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