纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1009 lines
44 KiB

3 years ago
  1. /**
  2. * jQuery Validation Plugin 1.9.0
  3. *
  4. * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
  5. * http://docs.jquery.com/Plugins/Validation
  6. *
  7. * Copyright (c) 2006 - 2011 Jörn Zaefferer
  8. *
  9. * Dual licensed under the MIT and GPL licenses:
  10. * http://www.opensource.org/licenses/mit-license.php
  11. * http://www.gnu.org/licenses/gpl.html
  12. */
  13. (function (c) {
  14. c.extend(c.fn, {
  15. validate: function (a) {
  16. if (this.length) {
  17. var b = c.data(this[0], "validator");
  18. if (b) return b;
  19. this.attr("novalidate", "novalidate");
  20. b = new c.validator(a, this[0]);
  21. c.data(this[0], "validator", b);
  22. if (b.settings.onsubmit) {
  23. a = this.find("input, button");
  24. a.filter(".cancel").click(function () {
  25. b.cancelSubmit = true
  26. });
  27. b.settings.submitHandler && a.filter(":submit").click(function () {
  28. b.submitButton = this
  29. });
  30. this.submit(function (d) {
  31. function e() {
  32. if (b.settings.submitHandler) {
  33. if (b.submitButton) var f = c("<input type='hidden'/>").attr("name",
  34. b.submitButton.name).val(b.submitButton.value).appendTo(b.currentForm);
  35. b.settings.submitHandler.call(b, b.currentForm);
  36. b.submitButton && f.remove();
  37. return false
  38. }
  39. return true
  40. }
  41. b.settings.debug && d.preventDefault();
  42. if (b.cancelSubmit) {
  43. b.cancelSubmit = false;
  44. return e()
  45. }
  46. if (b.form()) {
  47. if (b.pendingRequest) {
  48. b.formSubmitted = true;
  49. return false
  50. }
  51. return e()
  52. } else {
  53. b.focusInvalid();
  54. return false
  55. }
  56. })
  57. }
  58. return b
  59. } else a && a.debug && window.console && console.warn("nothing selected, can't validate, returning nothing")
  60. },
  61. valid: function (a) {
  62. if (c(this[0]).is("form")) return this.validate(a).form();
  63. else {
  64. var a = true,
  65. b = c(this[0].form).validate();
  66. this.each(function () {
  67. a &= b.element(this)
  68. });
  69. return a
  70. }
  71. },
  72. removeAttrs: function (a) {
  73. var b = {},
  74. d = this;
  75. c.each(a.split(/\s/),
  76. function (e, f) {
  77. b[f] = d.attr(f);
  78. d.removeAttr(f)
  79. });
  80. return b
  81. },
  82. rules: function (a, b) {
  83. var d = this[0];
  84. if (a) {
  85. var e = c.data(d.form, "validator").settings,
  86. f = e.rules,
  87. g = c.validator.staticRules(d);
  88. switch (a) {
  89. case "add":
  90. c.extend(g, c.validator.normalizeRule(b));
  91. f[d.name] = g;
  92. if (b.messages) e.messages[d.name] = c.extend(e.messages[d.name], b.messages);
  93. break;
  94. case "remove":
  95. if (!b) {
  96. delete f[d.name];
  97. return g
  98. }
  99. var h = {};
  100. c.each(b.split(/\s/),
  101. function (j, i) {
  102. h[i] = g[i];
  103. delete g[i]
  104. });
  105. return h
  106. }
  107. }
  108. d = c.validator.normalizeRules(c.extend({},
  109. c.validator.metadataRules(d), c.validator.classRules(d), c.validator.attributeRules(d), c.validator.staticRules(d)), d);
  110. if (d.required) {
  111. e = d.required;
  112. delete d.required;
  113. d = c.extend({
  114. required: e
  115. },
  116. d)
  117. }
  118. return d
  119. }
  120. });
  121. c.extend(c.expr[":"], {
  122. blank: function (a) {
  123. return !c.trim("" + a.value)
  124. },
  125. filled: function (a) {
  126. return !!c.trim("" + a.value)
  127. },
  128. unchecked: function (a) {
  129. return !a.checked
  130. }
  131. });
  132. c.validator = function (a,
  133. b) {
  134. this.settings = c.extend(true, {},
  135. c.validator.defaults, a);
  136. this.currentForm = b;
  137. this.init()
  138. };
  139. c.validator.format = function (a, b) {
  140. if (arguments.length == 1) return function () {
  141. var d = c.makeArray(arguments);
  142. d.unshift(a);
  143. return c.validator.format.apply(this, d)
  144. };
  145. if (arguments.length > 2 && b.constructor != Array) b = c.makeArray(arguments).slice(1);
  146. if (b.constructor != Array) b = [b];
  147. c.each(b,
  148. function (d, e) {
  149. a = a.replace(RegExp("\\{" + d + "\\}", "g"), e)
  150. });
  151. return a
  152. };
  153. c.extend(c.validator, {
  154. defaults: {
  155. messages: {},
  156. groups: {},
  157. rules: {},
  158. errorClass: "error",
  159. validClass: "valid",
  160. errorElement: "label",
  161. focusInvalid: true,
  162. errorContainer: c([]),
  163. errorLabelContainer: c([]),
  164. onsubmit: true,
  165. ignore: ":hidden",
  166. ignoreTitle: false,
  167. onfocusin: function (a) {
  168. this.lastActive = a;
  169. if (this.settings.focusCleanup && !this.blockFocusCleanup) {
  170. this.settings.unhighlight && this.settings.unhighlight.call(this, a, this.settings.errorClass, this.settings.validClass);
  171. this.addWrapper(this.errorsFor(a)).hide()
  172. }
  173. },
  174. onfocusout: function (a) {
  175. if (!this.checkable(a) && (a.name in this.submitted || !this.optional(a))) this.element(a)
  176. },
  177. onkeyup: function (a) {
  178. if (a.name in this.submitted || a == this.lastElement) this.element(a)
  179. },
  180. onclick: function (a) {
  181. if (a.name in this.submitted) this.element(a);
  182. else a.parentNode.name in this.submitted && this.element(a.parentNode)
  183. },
  184. highlight: function (a, b, d) {
  185. a.type === "radio" ? this.findByName(a.name).addClass(b).removeClass(d) : c(a).addClass(b).removeClass(d)
  186. },
  187. unhighlight: function (a, b, d) {
  188. a.type === "radio" ? this.findByName(a.name).removeClass(b).addClass(d) : c(a).removeClass(b).addClass(d)
  189. }
  190. },
  191. setDefaults: function (a) {
  192. c.extend(c.validator.defaults,
  193. a)
  194. },
  195. messages: {
  196. required: "必填字段",
  197. remote: "请修正该字段",
  198. email: "请输入正确格式的电子邮件",
  199. url: "请输入合法的网址",
  200. date: "请输入合法的日期",
  201. dateISO: "请输入合法的日期 (ISO).",
  202. number: "请输入合法的数字",
  203. digits: "只能输入整数",
  204. creditcard: "请输入合法的信用卡号",
  205. equalTo: "请再次输入相同的值",
  206. accept: "请输入拥有合法后缀名的字符串",
  207. maxlength: c.validator.format("请输入一个长度最多是 {0} 的字符串"),
  208. minlength: c.validator.format("请输入一个长度最少是 {0} 的字符串"),
  209. rangelength: c.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
  210. range: c.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
  211. max: c.validator.format("请输入一个最大为 {0} 的值"),
  212. min: c.validator.format("请输入一个最小为 {0} 的值")
  213. },
  214. autoCreateRanges: false,
  215. prototype: {
  216. init: function () {
  217. function a(e) {
  218. var f = c.data(this[0].form, "validator"),
  219. g = "on" + e.type.replace(/^validate/,
  220. "");
  221. f.settings[g] && f.settings[g].call(f, this[0], e)
  222. }
  223. this.labelContainer = c(this.settings.errorLabelContainer);
  224. this.errorContext = this.labelContainer.length && this.labelContainer || c(this.currentForm);
  225. this.containers = c(this.settings.errorContainer).add(this.settings.errorLabelContainer);
  226. this.submitted = {};
  227. this.valueCache = {};
  228. this.pendingRequest = 0;
  229. this.pending = {};
  230. this.invalid = {};
  231. this.reset();
  232. var b = this.groups = {};
  233. c.each(this.settings.groups,
  234. function (e, f) {
  235. c.each(f.split(/\s/),
  236. function (g, h) {
  237. b[h] = e
  238. })
  239. });
  240. var d =
  241. this.settings.rules;
  242. c.each(d,
  243. function (e, f) {
  244. d[e] = c.validator.normalizeRule(f)
  245. });
  246. c(this.currentForm).validateDelegate("[type='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", a).validateDelegate("[type='radio'], [type='checkbox'], select, option", "click",
  247. a);
  248. this.settings.invalidHandler && c(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler)
  249. },
  250. form: function () {
  251. this.checkForm();
  252. c.extend(this.submitted, this.errorMap);
  253. this.invalid = c.extend({},
  254. this.errorMap);
  255. this.valid() || c(this.currentForm).triggerHandler("invalid-form", [this]);
  256. this.showErrors();
  257. return this.valid()
  258. },
  259. checkForm: function () {
  260. this.prepareForm();
  261. for (var a = 0, b = this.currentElements = this.elements() ; b[a]; a++) this.check(b[a]);
  262. return this.valid()
  263. },
  264. element: function (a) {
  265. this.lastElement =
  266. a = this.validationTargetFor(this.clean(a));
  267. this.prepareElement(a);
  268. this.currentElements = c(a);
  269. var b = this.check(a);
  270. if (b) delete this.invalid[a.name];
  271. else this.invalid[a.name] = true;
  272. if (!this.numberOfInvalids()) this.toHide = this.toHide.add(this.containers);
  273. this.showErrors();
  274. return b
  275. },
  276. showErrors: function (a) {
  277. if (a) {
  278. c.extend(this.errorMap, a);
  279. this.errorList = [];
  280. for (var b in a) this.errorList.push({
  281. message: a[b],
  282. element: this.findByName(b)[0]
  283. });
  284. this.successList = c.grep(this.successList,
  285. function (d) {
  286. return !(d.name in a)
  287. })
  288. }
  289. this.settings.showErrors ?
  290. this.settings.showErrors.call(this, this.errorMap, this.errorList) : this.defaultShowErrors()
  291. },
  292. resetForm: function () {
  293. c.fn.resetForm && c(this.currentForm).resetForm();
  294. this.submitted = {};
  295. this.lastElement = null;
  296. this.prepareForm();
  297. this.hideErrors();
  298. this.elements().removeClass(this.settings.errorClass)
  299. },
  300. numberOfInvalids: function () {
  301. return this.objectLength(this.invalid)
  302. },
  303. objectLength: function (a) {
  304. var b = 0,
  305. d;
  306. for (d in a) b++;
  307. return b
  308. },
  309. hideErrors: function () {
  310. this.addWrapper(this.toHide).hide()
  311. },
  312. valid: function () {
  313. return this.size() ==
  314. 0
  315. },
  316. size: function () {
  317. return this.errorList.length
  318. },
  319. focusInvalid: function () {
  320. if (this.settings.focusInvalid) try {
  321. c(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus().trigger("focusin")
  322. } catch (a) { }
  323. },
  324. findLastActive: function () {
  325. var a = this.lastActive;
  326. return a && c.grep(this.errorList,
  327. function (b) {
  328. return b.element.name == a.name
  329. }).length == 1 && a
  330. },
  331. elements: function () {
  332. var a = this,
  333. b = {};
  334. return c(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, [disabled]").not(this.settings.ignore).filter(function () {
  335. !this.name &&
  336. a.settings.debug && window.console && console.error("%o has no name assigned", this);
  337. if (this.name in b || !a.objectLength(c(this).rules())) return false;
  338. return b[this.name] = true
  339. })
  340. },
  341. clean: function (a) {
  342. return c(a)[0]
  343. },
  344. errors: function () {
  345. return c(this.settings.errorElement + "." + this.settings.errorClass, this.errorContext)
  346. },
  347. reset: function () {
  348. this.successList = [];
  349. this.errorList = [];
  350. this.errorMap = {};
  351. this.toShow = c([]);
  352. this.toHide = c([]);
  353. this.currentElements = c([])
  354. },
  355. prepareForm: function () {
  356. this.reset();
  357. this.toHide = this.errors().add(this.containers)
  358. },
  359. prepareElement: function (a) {
  360. this.reset();
  361. this.toHide = this.errorsFor(a)
  362. },
  363. check: function (a) {
  364. a = this.validationTargetFor(this.clean(a));
  365. var b = c(a).rules(),
  366. d = false,
  367. e;
  368. for (e in b) {
  369. var f = {
  370. method: e,
  371. parameters: b[e]
  372. };
  373. try {
  374. var g = c.validator.methods[e].call(this, a.value.replace(/\r/g, ""), a, f.parameters);
  375. if (g == "dependency-mismatch") d = true;
  376. else {
  377. d = false;
  378. if (g == "pending") {
  379. this.toHide = this.toHide.not(this.errorsFor(a));
  380. return
  381. }
  382. if (!g) {
  383. this.formatAndAdd(a, f);
  384. return false
  385. }
  386. }
  387. } catch (h) {
  388. this.settings.debug && window.console && console.log("exception occured when checking element " +
  389. a.id + ", check the '" + f.method + "' method", h);
  390. throw h;
  391. }
  392. }
  393. if (!d) {
  394. this.objectLength(b) && this.successList.push(a);
  395. return true
  396. }
  397. },
  398. customMetaMessage: function (a, b) {
  399. if (c.metadata) {
  400. var d = this.settings.meta ? c(a).metadata()[this.settings.meta] : c(a).metadata();
  401. return d && d.messages && d.messages[b]
  402. }
  403. },
  404. customMessage: function (a, b) {
  405. var d = this.settings.messages[a];
  406. return d && (d.constructor == String ? d : d[b])
  407. },
  408. findDefined: function () {
  409. for (var a = 0; a < arguments.length; a++) if (arguments[a] !== undefined) return arguments[a]
  410. },
  411. defaultMessage: function (a,
  412. b) {
  413. return this.findDefined(this.customMessage(a.name, b), this.customMetaMessage(a, b), !this.settings.ignoreTitle && a.title || undefined, c.validator.messages[b], "<strong>Warning: No message defined for " + a.name + "</strong>")
  414. },
  415. formatAndAdd: function (a, b) {
  416. var d = this.defaultMessage(a, b.method),
  417. e = /\$?\{(\d+)\}/g;
  418. if (typeof d == "function") d = d.call(this, b.parameters, a);
  419. else if (e.test(d)) d = jQuery.format(d.replace(e, "{$1}"), b.parameters);
  420. this.errorList.push({
  421. message: d,
  422. element: a
  423. });
  424. this.errorMap[a.name] = d;
  425. this.submitted[a.name] =
  426. d
  427. },
  428. addWrapper: function (a) {
  429. if (this.settings.wrapper) a = a.add(a.parent(this.settings.wrapper));
  430. return a
  431. },
  432. defaultShowErrors: function () {
  433. for (var a = 0; this.errorList[a]; a++) {
  434. var b = this.errorList[a];
  435. this.settings.highlight && this.settings.highlight.call(this, b.element, this.settings.errorClass, this.settings.validClass);
  436. this.showLabel(b.element, b.message)
  437. }
  438. if (this.errorList.length) this.toShow = this.toShow.add(this.containers);
  439. if (this.settings.success) for (a = 0; this.successList[a]; a++) this.showLabel(this.successList[a]);
  440. if (this.settings.unhighlight) {
  441. a = 0;
  442. for (b = this.validElements() ; b[a]; a++) this.settings.unhighlight.call(this, b[a], this.settings.errorClass, this.settings.validClass)
  443. }
  444. this.toHide = this.toHide.not(this.toShow);
  445. this.hideErrors();
  446. this.addWrapper(this.toShow).show()
  447. },
  448. validElements: function () {
  449. return this.currentElements.not(this.invalidElements())
  450. },
  451. invalidElements: function () {
  452. return c(this.errorList).map(function () {
  453. return this.element
  454. })
  455. },
  456. showLabel: function (a, b) {
  457. var d = this.errorsFor(a);
  458. if (d.length) {
  459. d.removeClass(this.settings.validClass).addClass(this.settings.errorClass);
  460. d.attr("generated") && d.html(b)
  461. } else {
  462. d = c("<" + this.settings.errorElement + "/>").attr({
  463. "for": this.idOrName(a),
  464. generated: true
  465. }).addClass(this.settings.errorClass).html(b || "");
  466. if (this.settings.wrapper) d = d.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
  467. this.labelContainer.append(d).length || (this.settings.errorPlacement ? this.settings.errorPlacement(d.text(), c(a)) : d.insertAfter(a))
  468. }
  469. if (!b && this.settings.success) {
  470. d.text("");
  471. typeof this.settings.success == "string" ? d.addClass(this.settings.success) : this.settings.success(c(a))
  472. }
  473. this.toShow =
  474. this.toShow.add(d)
  475. },
  476. errorsFor: function (a) {
  477. var b = this.idOrName(a);
  478. return this.errors().filter(function () {
  479. return c(this).attr("for") == b
  480. })
  481. },
  482. idOrName: function (a) {
  483. return this.groups[a.name] || (this.checkable(a) ? a.name : a.id || a.name)
  484. },
  485. validationTargetFor: function (a) {
  486. if (this.checkable(a)) a = this.findByName(a.name).not(this.settings.ignore)[0];
  487. return a
  488. },
  489. checkable: function (a) {
  490. return /radio|checkbox/i.test(a.type)
  491. },
  492. findByName: function (a) {
  493. var b = this.currentForm;
  494. return c(document.getElementsByName(a)).map(function (d,
  495. e) {
  496. return e.form == b && e.name == a && e || null
  497. })
  498. },
  499. getLength: function (a, b) {
  500. switch (b.nodeName.toLowerCase()) {
  501. case "select":
  502. return c("option:selected", b).length;
  503. case "input":
  504. if (this.checkable(b)) return this.findByName(b.name).filter(":checked").length
  505. }
  506. return a.length
  507. },
  508. depend: function (a, b) {
  509. return this.dependTypes[typeof a] ? this.dependTypes[typeof a](a, b) : true
  510. },
  511. dependTypes: {
  512. "boolean": function (a) {
  513. return a
  514. },
  515. string: function (a, b) {
  516. return !!c(a, b.form).length
  517. },
  518. "function": function (a, b) {
  519. return a(b)
  520. }
  521. },
  522. optional: function (a) {
  523. return !c.validator.methods.required.call(this,
  524. c.trim(a.value), a) && "dependency-mismatch"
  525. },
  526. startRequest: function (a) {
  527. if (!this.pending[a.name]) {
  528. this.pendingRequest++;
  529. this.pending[a.name] = true
  530. }
  531. },
  532. stopRequest: function (a, b) {
  533. this.pendingRequest--;
  534. if (this.pendingRequest < 0) this.pendingRequest = 0;
  535. delete this.pending[a.name];
  536. if (b && this.pendingRequest == 0 && this.formSubmitted && this.form()) {
  537. c(this.currentForm).submit();
  538. this.formSubmitted = false
  539. } else if (!b && this.pendingRequest == 0 && this.formSubmitted) {
  540. c(this.currentForm).triggerHandler("invalid-form", [this]);
  541. this.formSubmitted =
  542. false
  543. }
  544. },
  545. previousValue: function (a) {
  546. return c.data(a, "previousValue") || c.data(a, "previousValue", {
  547. old: null,
  548. valid: true,
  549. message: this.defaultMessage(a, "remote")
  550. })
  551. }
  552. },
  553. classRuleSettings: {
  554. required: {
  555. required: true
  556. },
  557. email: {
  558. email: true
  559. },
  560. url: {
  561. url: true
  562. },
  563. date: {
  564. date: true
  565. },
  566. dateISO: {
  567. dateISO: true
  568. },
  569. dateDE: {
  570. dateDE: true
  571. },
  572. number: {
  573. number: true
  574. },
  575. numberDE: {
  576. numberDE: true
  577. },
  578. digits: {
  579. digits: true
  580. },
  581. creditcard: {
  582. creditcard: true
  583. }
  584. },
  585. addClassRules: function (a, b) {
  586. a.constructor == String ? this.classRuleSettings[a] = b : c.extend(this.classRuleSettings,
  587. a)
  588. },
  589. classRules: function (a) {
  590. var b = {}; (a = c(a).attr("class")) && c.each(a.split(" "),
  591. function () {
  592. this in c.validator.classRuleSettings && c.extend(b, c.validator.classRuleSettings[this])
  593. });
  594. return b
  595. },
  596. attributeRules: function (a) {
  597. var b = {};
  598. a = c(a);
  599. for (var d in c.validator.methods) {
  600. var e;
  601. if (e = d === "required" && typeof c.fn.prop === "function" ? a.prop(d) : a.attr(d)) b[d] = e;
  602. else if (a[0].getAttribute("type") === d) b[d] = true
  603. }
  604. b.maxlength && /-1|2147483647|524288/.test(b.maxlength) && delete b.maxlength;
  605. return b
  606. },
  607. metadataRules: function (a) {
  608. if (!c.metadata) return {};
  609. var b = c.data(a.form, "validator").settings.meta;
  610. return b ? c(a).metadata()[b] : c(a).metadata()
  611. },
  612. staticRules: function (a) {
  613. var b = {},
  614. d = c.data(a.form, "validator");
  615. if (d.settings.rules) b = c.validator.normalizeRule(d.settings.rules[a.name]) || {};
  616. return b
  617. },
  618. normalizeRules: function (a, b) {
  619. c.each(a,
  620. function (d, e) {
  621. if (e === false) delete a[d];
  622. else if (e.param || e.depends) {
  623. var f = true;
  624. switch (typeof e.depends) {
  625. case "string":
  626. f = !!c(e.depends, b.form).length;
  627. break;
  628. case "function":
  629. f = e.depends.call(b, b)
  630. }
  631. if (f) a[d] = e.param !== undefined ?
  632. e.param : true;
  633. else delete a[d]
  634. }
  635. });
  636. c.each(a,
  637. function (d, e) {
  638. a[d] = c.isFunction(e) ? e(b) : e
  639. });
  640. c.each(["minlength", "maxlength", "min", "max"],
  641. function () {
  642. if (a[this]) a[this] = Number(a[this])
  643. });
  644. c.each(["rangelength", "range"],
  645. function () {
  646. if (a[this]) a[this] = [Number(a[this][0]), Number(a[this][1])]
  647. });
  648. if (c.validator.autoCreateRanges) {
  649. if (a.min && a.max) {
  650. a.range = [a.min, a.max];
  651. delete a.min;
  652. delete a.max
  653. }
  654. if (a.minlength && a.maxlength) {
  655. a.rangelength = [a.minlength, a.maxlength];
  656. delete a.minlength;
  657. delete a.maxlength
  658. }
  659. }
  660. a.messages && delete a.messages;
  661. return a
  662. },
  663. normalizeRule: function (a) {
  664. if (typeof a == "string") {
  665. var b = {};
  666. c.each(a.split(/\s/),
  667. function () {
  668. b[this] = true
  669. });
  670. a = b
  671. }
  672. return a
  673. },
  674. addMethod: function (a, b, d) {
  675. c.validator.methods[a] = b;
  676. c.validator.messages[a] = d != undefined ? d : c.validator.messages[a];
  677. b.length < 3 && c.validator.addClassRules(a, c.validator.normalizeRule(a))
  678. },
  679. methods: {
  680. required: function (a, b, d) {
  681. if (!this.depend(d, b)) return "dependency-mismatch";
  682. switch (b.nodeName.toLowerCase()) {
  683. case "select":
  684. return (a = c(b).val()) && a.length > 0;
  685. case "input":
  686. if (this.checkable(b)) return this.getLength(a,
  687. b) > 0;
  688. default:
  689. return c.trim(a).length > 0
  690. }
  691. },
  692. remote: function (a, b, d) {
  693. if (this.optional(b)) return "dependency-mismatch";
  694. var e = this.previousValue(b);
  695. this.settings.messages[b.name] || (this.settings.messages[b.name] = {});
  696. e.originalMessage = this.settings.messages[b.name].remote;
  697. this.settings.messages[b.name].remote = e.message;
  698. d = typeof d == "string" && {
  699. url: d
  700. } || d;
  701. if (this.pending[b.name]) return "pending";
  702. if (e.old === a) return e.valid;
  703. e.old = a;
  704. var f = this;
  705. this.startRequest(b);
  706. var g = {};
  707. g[b.name] = a;
  708. c.ajax(c.extend(true, {
  709. url: d,
  710. mode: "abort",
  711. port: "validate" + b.name,
  712. dataType: "json",
  713. data: g,
  714. success: function (h) {
  715. f.settings.messages[b.name].remote = e.originalMessage;
  716. var j = h === true;
  717. if (j) {
  718. var i = f.formSubmitted;
  719. f.prepareElement(b);
  720. f.formSubmitted = i;
  721. f.successList.push(b);
  722. f.showErrors()
  723. } else {
  724. i = {};
  725. h = h || f.defaultMessage(b, "remote");
  726. i[b.name] = e.message = c.isFunction(h) ? h(a) : h;
  727. f.showErrors(i)
  728. }
  729. e.valid = j;
  730. f.stopRequest(b, j)
  731. }
  732. },
  733. d));
  734. return "pending"
  735. },
  736. minlength: function (a, b, d) {
  737. return this.optional(b) || this.getLength(c.trim(a), b) >= d
  738. },
  739. maxlength: function (a,
  740. b, d) {
  741. return this.optional(b) || this.getLength(c.trim(a), b) <= d
  742. },
  743. rangelength: function (a, b, d) {
  744. a = this.getLength(c.trim(a), b);
  745. return this.optional(b) || a >= d[0] && a <= d[1]
  746. },
  747. min: function (a, b, d) {
  748. return this.optional(b) || a >= d
  749. },
  750. max: function (a, b, d) {
  751. return this.optional(b) || a <= d
  752. },
  753. range: function (a, b, d) {
  754. return this.optional(b) || a >= d[0] && a <= d[1]
  755. },
  756. email: function (a, b) {
  757. return this.optional(b) || /^((([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(a)
  758. },
  759. url: function (a, b) {
  760. return this.optional(b) || /^(https?|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(a)
  761. },
  762. date: function (a, b) {
  763. return this.optional(b) || !/Invalid|NaN/.test(new Date(a))
  764. },
  765. dateISO: function (a, b) {
  766. return this.optional(b) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(a)
  767. },
  768. number: function (a, b) {
  769. return this.optional(b) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(a)
  770. },
  771. digits: function (a, b) {
  772. return this.optional(b) || /^\d+$/.test(a)
  773. },
  774. creditcard: function (a, b) {
  775. if (this.optional(b)) return "dependency-mismatch";
  776. if (/[^0-9 -]+/.test(a)) return false;
  777. var d = 0,
  778. e = 0,
  779. f = false;
  780. a = a.replace(/\D/g, "");
  781. for (var g = a.length - 1; g >=
  782. 0; g--) {
  783. e = a.charAt(g);
  784. e = parseInt(e, 10);
  785. if (f) if ((e *= 2) > 9) e -= 9;
  786. d += e;
  787. f = !f
  788. }
  789. return d % 10 == 0
  790. },
  791. accept: function (a, b, d) {
  792. d = typeof d == "string" ? d.replace(/,/g, "|") : "png|jpe?g|gif";
  793. return this.optional(b) || a.match(RegExp(".(" + d + ")$", "i"))
  794. },
  795. equalTo: function (a, b, d) {
  796. d = c(d).unbind(".validate-equalTo").bind("blur.validate-equalTo",
  797. function () {
  798. c(b).valid()
  799. });
  800. return a == d.val()
  801. }
  802. }
  803. });
  804. c.format = c.validator.format
  805. })(jQuery);
  806. (function (c) {
  807. var a = {};
  808. if (c.ajaxPrefilter) c.ajaxPrefilter(function (d, e, f) {
  809. e = d.port;
  810. if (d.mode == "abort") {
  811. a[e] && a[e].abort();
  812. a[e] = f
  813. }
  814. });
  815. else {
  816. var b = c.ajax;
  817. c.ajax = function (d) {
  818. var e = ("port" in d ? d : c.ajaxSettings).port;
  819. if (("mode" in d ? d : c.ajaxSettings).mode == "abort") {
  820. a[e] && a[e].abort();
  821. return a[e] = b.apply(this, arguments)
  822. }
  823. return b.apply(this, arguments)
  824. }
  825. }
  826. })(jQuery);
  827. (function (c) {
  828. !jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener && c.each({
  829. focus: "focusin",
  830. blur: "focusout"
  831. },
  832. function (a, b) {
  833. function d(e) {
  834. e = c.event.fix(e);
  835. e.type = b;
  836. return c.event.handle.call(this, e)
  837. }
  838. c.event.special[b] = {
  839. setup: function () {
  840. this.addEventListener(a, d, true)
  841. },
  842. teardown: function () {
  843. this.removeEventListener(a, d, true)
  844. },
  845. handler: function (e) {
  846. arguments[0] = c.event.fix(e);
  847. arguments[0].type = b;
  848. return c.event.handle.apply(this, arguments)
  849. }
  850. }
  851. });
  852. c.extend(c.fn, {
  853. validateDelegate: function (a,
  854. b, d) {
  855. return this.bind(b,
  856. function (e) {
  857. var f = c(e.target);
  858. if (f.is(a)) return d.apply(f, arguments)
  859. })
  860. }
  861. })
  862. })(jQuery);
  863. /*****************************************************************
  864. jQuery Validate扩展验证方法
  865. *****************************************************************/
  866. $(function () {
  867. // 判断整数value是否等于0
  868. jQuery.validator.addMethod("isIntEqZero", function (value, element) {
  869. value = parseInt(value);
  870. return this.optional(element) || value == 0;
  871. }, "整数必须为0");
  872. // 判断整数value是否大于0
  873. jQuery.validator.addMethod("isIntGtZero", function (value, element) {
  874. value = parseInt(value);
  875. return this.optional(element) || value > 0;
  876. }, "整数必须大于0");
  877. // 判断整数value是否大于或等于0
  878. jQuery.validator.addMethod("isIntGteZero", function (value, element) {
  879. value = parseInt(value);
  880. return this.optional(element) || value >= 0;
  881. }, "整数必须大于或等于0");
  882. // 判断整数value是否不等于0
  883. jQuery.validator.addMethod("isIntNEqZero", function (value, element) {
  884. value = parseInt(value);
  885. return this.optional(element) || value != 0;
  886. }, "整数必须不等于0");
  887. // 判断整数value是否小于0
  888. jQuery.validator.addMethod("isIntLtZero", function (value, element) {
  889. value = parseInt(value);
  890. return this.optional(element) || value < 0;
  891. }, "整数必须小于0");
  892. // 判断整数value是否小于或等于0
  893. jQuery.validator.addMethod("isIntLteZero", function (value, element) {
  894. value = parseInt(value);
  895. return this.optional(element) || value <= 0;
  896. }, "整数必须小于或等于0");
  897. // 判断浮点数value是否等于0
  898. jQuery.validator.addMethod("isFloatEqZero", function (value, element) {
  899. value = parseFloat(value);
  900. return this.optional(element) || value == 0;
  901. }, "浮点数必须为0");
  902. // 判断浮点数value是否大于0
  903. jQuery.validator.addMethod("isFloatGtZero", function (value, element) {
  904. value = parseFloat(value);
  905. return this.optional(element) || value > 0;
  906. }, "浮点数必须大于0");
  907. // 判断浮点数value是否大于或等于0
  908. jQuery.validator.addMethod("isFloatGteZero", function (value, element) {
  909. value = parseFloat(value);
  910. return this.optional(element) || value >= 0;
  911. }, "浮点数必须大于或等于0");
  912. // 判断浮点数value是否不等于0
  913. jQuery.validator.addMethod("isFloatNEqZero", function (value, element) {
  914. value = parseFloat(value);
  915. return this.optional(element) || value != 0;
  916. }, "浮点数必须不等于0");
  917. // 判断浮点数value是否小于0
  918. jQuery.validator.addMethod("isFloatLtZero", function (value, element) {
  919. value = parseFloat(value);
  920. return this.optional(element) || value < 0;
  921. }, "浮点数必须小于0");
  922. // 判断浮点数value是否小于或等于0
  923. jQuery.validator.addMethod("isFloatLteZero", function (value, element) {
  924. value = parseFloat(value);
  925. return this.optional(element) || value <= 0;
  926. }, "浮点数必须小于或等于0");
  927. // 判断浮点型
  928. jQuery.validator.addMethod("isFloat", function (value, element) {
  929. return this.optional(element) || /^[-\+]?\d+(\.\d+)?$/.test(value);
  930. }, "只能包含数字、小数点等字符");
  931. // 匹配integer
  932. jQuery.validator.addMethod("isInteger", function (value, element) {
  933. return this.optional(element) || (/^[-\+]?\d+$/.test(value) && parseInt(value) >= 0);
  934. }, "匹配integer");
  935. // 判断数值类型,包括整数和浮点数
  936. jQuery.validator.addMethod("isNumber", function (value, element) {
  937. return this.optional(element) || /^[-\+]?\d+$/.test(value) || /^[-\+]?\d+(\.\d+)?$/.test(value);
  938. }, "匹配数值类型,包括整数和浮点数");
  939. // 只能输入[0-9]数字
  940. jQuery.validator.addMethod("isDigits", function (value, element) {
  941. return this.optional(element) || /^\d+$/.test(value);
  942. }, "只能输入0-9数字");
  943. // 判断中文字符
  944. jQuery.validator.addMethod("isChinese", function (value, element) {
  945. return this.optional(element) || /^[\u0391-\uFFE5]+$/.test(value);
  946. }, "只能包含中文字符。");
  947. // 判断英文字符
  948. jQuery.validator.addMethod("isEnglish", function (value, element) {
  949. return this.optional(element) || /^[A-Za-z]+$/.test(value);
  950. }, "只能包含英文字符。");
  951. // 手机号码验证
  952. jQuery.validator.addMethod("isMobile", function (value, element) {
  953. var length = value.length;
  954. return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value));
  955. }, "请正确填写您的手机号码。");
  956. // 电话号码验证
  957. jQuery.validator.addMethod("isPhone", function (value, element) {
  958. var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
  959. return this.optional(element) || (tel.test(value));
  960. }, "请正确填写您的电话号码。");
  961. // 联系电话(手机/电话皆可)验证
  962. jQuery.validator.addMethod("isTel", function (value, element) {
  963. var length = value.length;
  964. var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  965. var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
  966. return this.optional(element) || tel.test(value) || (length == 11 && mobile.test(value));
  967. }, "请正确填写您的联系方式");
  968. // 匹配qq
  969. jQuery.validator.addMethod("isQq", function (value, element) {
  970. return this.optional(element) || /^[1-9]\d{4,12}$/;
  971. }, "匹配QQ");
  972. // 邮政编码验证
  973. jQuery.validator.addMethod("isZipCode", function (value, element) {
  974. var zip = /^[0-9]{6}$/;
  975. return this.optional(element) || (zip.test(value));
  976. }, "请正确填写您的邮政编码。");
  977. // 匹配密码,以字母开头,长度在6-12之间,只能包含字符、数字和下划线。
  978. jQuery.validator.addMethod("isPwd", function (value, element) {
  979. return this.optional(element) || /^[a-zA-Z]\\w{6,12}$/.test(value);
  980. }, "以字母开头,长度在6-12之间,只能包含字符、数字和下划线。");
  981. // IP地址验证
  982. jQuery.validator.addMethod("ip", function (value, element) {
  983. return this.optional(element) || /^(([0-9]|([0-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([0-9]|([0-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([0-9]|([0-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))$/.test(value);
  984. }, "请填写正确的IP地址。");
  985. // 字符验证,只能包含中文、英文、数字、下划线等字符。
  986. jQuery.validator.addMethod("stringCheck", function (value, element) {
  987. return this.optional(element) || /^[a-zA-Z0-9\u4e00-\u9fa5-_]+$/.test(value);
  988. }, "只能包含中文、英文、数字、下划线等字符");
  989. // 匹配english
  990. jQuery.validator.addMethod("isEnglish", function (value, element) {
  991. return this.optional(element) || /^[A-Za-z]+$/.test(value);
  992. }, "匹配english");
  993. // 匹配汉字
  994. jQuery.validator.addMethod("isChinese", function (value, element) {
  995. return this.optional(element) || /^[\u4e00-\u9fa5]+$/.test(value);
  996. }, "匹配汉字");
  997. // 匹配中文(包括汉字和字符)
  998. jQuery.validator.addMethod("isChineseChar", function (value, element) {
  999. return this.optional(element) || /^[\u0391-\uFFE5]+$/.test(value);
  1000. }, "匹配中文(包括汉字和字符) ");
  1001. // 判断是否为合法字符(a-zA-Z0-9-_)
  1002. jQuery.validator.addMethod("isRightfulString", function (value, element) {
  1003. return this.optional(element) || /^[A-Za-z0-9_-]+$/.test(value);
  1004. }, "判断是否为合法字符(a-zA-Z0-9-_)");
  1005. // 判断是否包含中英文特殊字符,除英文"-_"字符外
  1006. jQuery.validator.addMethod("isContainsSpecialChar", function (value, element) {
  1007. var reg = RegExp(/[(\ )(\`)(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\+)(\=)(\|)(\{)(\})(\')(\:)(\;)(\')(',)(\[)(\])(\.)(\<)(\>)(\/)(\?)(\~)(\!)(\@)(\#)(\¥)(\%)(\…)(\&)(\*)(\()(\))(\—)(\+)(\|)(\{)(\})(\【)(\】)(\‘)(\;)(\:)(\”)(\“)(\’)(\。)(\,)(\、)(\?)]+/);
  1008. return this.optional(element) || !reg.test(value);
  1009. }, "含有中英文特殊字符");
  1010. });