jquery.validate.min_v1.8.0.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /**
  2. * jQuery Validation Plugin 1.8.0
  3. *
  4. * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ http://docs.jquery.com/Plugins/Validation
  5. *
  6. * Copyright (c) 2006 - 2011 Jörn Zaefferer
  7. *
  8. * Dual licensed under the MIT and GPL licenses: http://www.opensource.org/licenses/mit-license.php
  9. * http://www.gnu.org/licenses/gpl.html
  10. */
  11. (function(c) {
  12. c.extend(c.fn, {
  13. validate : function(a) {
  14. if (this.length) {
  15. var b = c.data(this[0], "validator");
  16. if (b)
  17. return b;
  18. b = new c.validator(a, this[0]);
  19. c.data(this[0], "validator", b);
  20. if (b.settings.onsubmit) {
  21. this.find("input, button").filter(".cancel").click(function() {
  22. b.cancelSubmit = true
  23. });
  24. b.settings.submitHandler && this.find("input, button").filter(":submit").click(function() {
  25. b.submitButton = this
  26. });
  27. this.submit(function(d) {
  28. function e() {
  29. if (b.settings.submitHandler) {
  30. if (b.submitButton)
  31. var f = c("<input type='hidden'/>").attr("name", b.submitButton.name).val(
  32. b.submitButton.value).appendTo(b.currentForm);
  33. b.settings.submitHandler.call(b, b.currentForm);
  34. b.submitButton && f.remove();
  35. return false
  36. }
  37. return true
  38. }
  39. b.settings.debug && d.preventDefault();
  40. if (b.cancelSubmit) {
  41. b.cancelSubmit = false;
  42. return e()
  43. }
  44. if (b.form()) {
  45. if (b.pendingRequest) {
  46. b.formSubmitted = true;
  47. return false
  48. }
  49. return e()
  50. } else {
  51. b.focusInvalid();
  52. return false
  53. }
  54. })
  55. }
  56. return b
  57. } else
  58. a && a.debug && window.console && console.warn("nothing selected, can't validate, returning nothing")
  59. },
  60. valid : function() {
  61. if (c(this[0]).is("form"))
  62. return this.validate().form();
  63. else {
  64. var a = true, b = c(this[0].form).validate();
  65. this.each(function() {
  66. a &= b.element(this)
  67. });
  68. return a
  69. }
  70. },
  71. removeAttrs : function(a) {
  72. var b = {}, d = this;
  73. c.each(a.split(/\s/), function(e, f) {
  74. b[f] = d.attr(f);
  75. d.removeAttr(f)
  76. });
  77. return b
  78. },
  79. rules : function(a, b) {
  80. var d = this[0];
  81. if (a) {
  82. var e = c.data(d.form, "validator").settings, f = e.rules, g = c.validator.staticRules(d);
  83. switch (a) {
  84. case "add":
  85. c.extend(g, c.validator.normalizeRule(b));
  86. f[d.name] = g;
  87. if (b.messages)
  88. e.messages[d.name] = c.extend(e.messages[d.name], b.messages);
  89. break;
  90. case "remove":
  91. if (!b) {
  92. delete f[d.name];
  93. return g
  94. }
  95. var h = {};
  96. c.each(b.split(/\s/), function(j, i) {
  97. h[i] = g[i];
  98. delete g[i]
  99. });
  100. return h
  101. }
  102. }
  103. d = c.validator.normalizeRules(c.extend({}, c.validator.metadataRules(d), c.validator.classRules(d),
  104. c.validator.attributeRules(d), c.validator.staticRules(d)), d);
  105. if (d.required) {
  106. e = d.required;
  107. delete d.required;
  108. d = c.extend({
  109. required : e
  110. }, d)
  111. }
  112. return d
  113. }
  114. });
  115. c.extend(c.expr[":"], {
  116. blank : function(a) {
  117. return !c.trim("" + a.value)
  118. },
  119. filled : function(a) {
  120. return !!c.trim("" + a.value)
  121. },
  122. unchecked : function(a) {
  123. return !a.checked
  124. }
  125. });
  126. c.validator = function(a, b) {
  127. this.settings = c.extend(true, {}, c.validator.defaults, a);
  128. this.currentForm = b;
  129. this.init()
  130. };
  131. c.validator.format = function(a, b) {
  132. if (arguments.length == 1)
  133. return function() {
  134. var d = c.makeArray(arguments);
  135. d.unshift(a);
  136. return c.validator.format.apply(this, d)
  137. };
  138. if (arguments.length > 2 && b.constructor != Array)
  139. b = c.makeArray(arguments).slice(1);
  140. if (b.constructor != Array)
  141. b = [ b ];
  142. c.each(b, function(d, e) {
  143. a = a.replace(RegExp("\\{" + d + "\\}", "g"), e)
  144. });
  145. return a
  146. };
  147. c
  148. .extend(
  149. c.validator,
  150. {
  151. defaults : {
  152. messages : {},
  153. groups : {},
  154. rules : {},
  155. errorClass : "error",
  156. validClass : "valid",
  157. errorElement : "label",
  158. focusInvalid : true,
  159. errorContainer : c([]),
  160. errorLabelContainer : c([]),
  161. onsubmit : true,
  162. ignore : [],
  163. ignoreTitle : false,
  164. onfocusin : function(a) {
  165. this.lastActive = a;
  166. if (this.settings.focusCleanup && !this.blockFocusCleanup) {
  167. this.settings.unhighlight
  168. && this.settings.unhighlight.call(this, a, this.settings.errorClass,
  169. this.settings.validClass);
  170. this.addWrapper(this.errorsFor(a)).hide()
  171. }
  172. },
  173. onfocusout : function(a) {
  174. if (!this.checkable(a) && (a.name in this.submitted || !this.optional(a)))
  175. this.element(a)
  176. },
  177. onkeyup : function(a) {
  178. if (a.name in this.submitted || a == this.lastElement)
  179. this.element(a)
  180. },
  181. onclick : function(a) {
  182. if (a.name in this.submitted)
  183. this.element(a);
  184. else
  185. a.parentNode.name in this.submitted && this.element(a.parentNode)
  186. },
  187. highlight : function(a, b, d) {
  188. c(a).addClass(b).removeClass(d)
  189. },
  190. unhighlight : function(a, b, d) {
  191. c(a).removeClass(b).addClass(d)
  192. }
  193. },
  194. setDefaults : function(a) {
  195. c.extend(c.validator.defaults, a)
  196. },
  197. messages : {
  198. required : "This field is required.",
  199. remote : "Please fix this field.",
  200. email : "Please enter a valid email address.",
  201. url : "Please enter a valid URL.",
  202. date : "Please enter a valid date.",
  203. dateISO : "Please enter a valid date (ISO).",
  204. number : "Please enter a valid number.",
  205. digits : "Please enter only digits.",
  206. creditcard : "Please enter a valid credit card number.",
  207. equalTo : "Please enter the same value again.",
  208. accept : "Please enter a value with a valid extension.",
  209. maxlength : c.validator.format("Please enter no more than {0} characters."),
  210. minlength : c.validator.format("Please enter at least {0} characters."),
  211. rangelength : c.validator
  212. .format("Please enter a value between {0} and {1} characters long."),
  213. range : c.validator.format("Please enter a value between {0} and {1}."),
  214. max : c.validator.format("Please enter a value less than or equal to {0}."),
  215. min : c.validator.format("Please enter a value greater than or equal to {0}.")
  216. },
  217. autoCreateRanges : false,
  218. prototype : {
  219. init : function() {
  220. function a(e) {
  221. var f = c.data(this[0].form, "validator");
  222. e = "on" + e.type.replace(/^validate/, "");
  223. f.settings[e] && f.settings[e].call(f, this[0])
  224. }
  225. this.labelContainer = c(this.settings.errorLabelContainer);
  226. this.errorContext = this.labelContainer.length && this.labelContainer
  227. || c(this.currentForm);
  228. this.containers = c(this.settings.errorContainer)
  229. .add(this.settings.errorLabelContainer);
  230. this.submitted = {};
  231. this.valueCache = {};
  232. this.pendingRequest = 0;
  233. this.pending = {};
  234. this.invalid = {};
  235. this.reset();
  236. var b = this.groups = {};
  237. c.each(this.settings.groups, function(e, f) {
  238. c.each(f.split(/\s/), function(g, h) {
  239. b[h] = e
  240. })
  241. });
  242. var d = this.settings.rules;
  243. c.each(d, function(e, f) {
  244. d[e] = c.validator.normalizeRule(f)
  245. });
  246. c(this.currentForm).validateDelegate(":text, :password, :file, select, textarea",
  247. "focusin focusout keyup", a).validateDelegate(
  248. ":radio, :checkbox, select, option", "click", a);
  249. this.settings.invalidHandler
  250. && c(this.currentForm).bind("invalid-form.validate",
  251. this.settings.invalidHandler)
  252. },
  253. form : function() {
  254. this.checkForm();
  255. c.extend(this.submitted, this.errorMap);
  256. this.invalid = c.extend({}, this.errorMap);
  257. this.valid() || c(this.currentForm).triggerHandler("invalid-form", [ this ]);
  258. this.showErrors();
  259. return this.valid()
  260. },
  261. checkForm : function() {
  262. this.prepareForm();
  263. for ( var a = 0, b = this.currentElements = this.elements(); b[a]; a++)
  264. this.check(b[a]);
  265. return this.valid()
  266. },
  267. element : function(a) {
  268. this.lastElement = a = this.clean(a);
  269. this.prepareElement(a);
  270. this.currentElements = c(a);
  271. var b = this.check(a);
  272. if (b)
  273. delete this.invalid[a.name];
  274. else
  275. this.invalid[a.name] = true;
  276. if (!this.numberOfInvalids())
  277. this.toHide = this.toHide.add(this.containers);
  278. this.showErrors();
  279. return b
  280. },
  281. showErrors : function(a) {
  282. if (a) {
  283. c.extend(this.errorMap, a);
  284. this.errorList = [];
  285. for ( var b in a)
  286. this.errorList.push({
  287. message : a[b],
  288. element : this.findByName(b)[0]
  289. });
  290. this.successList = c.grep(this.successList, function(d) {
  291. return !(d.name in a)
  292. })
  293. }
  294. this.settings.showErrors ? this.settings.showErrors.call(this, this.errorMap,
  295. this.errorList) : this.defaultShowErrors()
  296. },
  297. resetForm : function() {
  298. c.fn.resetForm && c(this.currentForm).resetForm();
  299. this.submitted = {};
  300. this.prepareForm();
  301. this.hideErrors();
  302. this.elements().removeClass(this.settings.errorClass)
  303. },
  304. numberOfInvalids : function() {
  305. return this.objectLength(this.invalid)
  306. },
  307. objectLength : function(a) {
  308. var b = 0, d;
  309. for (d in a)
  310. b++;
  311. return b
  312. },
  313. hideErrors : function() {
  314. this.addWrapper(this.toHide).hide()
  315. },
  316. valid : function() {
  317. return this.size() == 0
  318. },
  319. size : function() {
  320. return this.errorList.length
  321. },
  322. focusInvalid : function() {
  323. if (this.settings.focusInvalid)
  324. try {
  325. c(
  326. this.findLastActive() || this.errorList.length
  327. && this.errorList[0].element || []).filter(":visible").focus()
  328. .trigger("focusin")
  329. } catch (a) {
  330. }
  331. },
  332. findLastActive : function() {
  333. var a = this.lastActive;
  334. return a && c.grep(this.errorList, function(b) {
  335. return b.element.name == a.name
  336. }).length == 1 && a
  337. },
  338. elements : function() {
  339. var a = this, b = {};
  340. return c([]).add(this.currentForm.elements).filter(":input").not(
  341. ":submit, :reset, :image, [disabled]").not(this.settings.ignore).filter(
  342. function() {
  343. !this.name && a.settings.debug && window.console
  344. && console.error("%o has no name assigned", this);
  345. if (this.name in b || !a.objectLength(c(this).rules()))
  346. return false;
  347. return b[this.name] = true
  348. })
  349. },
  350. clean : function(a) {
  351. return c(a)[0]
  352. },
  353. errors : function() {
  354. return c(this.settings.errorElement + "." + this.settings.errorClass, this.errorContext)
  355. },
  356. reset : function() {
  357. this.successList = [];
  358. this.errorList = [];
  359. this.errorMap = {};
  360. this.toShow = c([]);
  361. this.toHide = c([]);
  362. this.currentElements = c([])
  363. },
  364. prepareForm : function() {
  365. this.reset();
  366. this.toHide = this.errors().add(this.containers)
  367. },
  368. prepareElement : function(a) {
  369. this.reset();
  370. this.toHide = this.errorsFor(a)
  371. },
  372. check : function(a) {
  373. a = this.clean(a);
  374. if (this.checkable(a))
  375. a = this.findByName(a.name).not(this.settings.ignore)[0];
  376. var b = c(a).rules(), d = false, e;
  377. for (e in b) {
  378. var f = {
  379. method : e,
  380. parameters : b[e]
  381. };
  382. try {
  383. var g = c.validator.methods[e].call(this, a.value.replace(/\r/g, ""), a,
  384. f.parameters);
  385. if (g == "dependency-mismatch")
  386. d = true;
  387. else {
  388. d = false;
  389. if (g == "pending") {
  390. this.toHide = this.toHide.not(this.errorsFor(a));
  391. return
  392. }
  393. if (!g) {
  394. this.formatAndAdd(a, f);
  395. return false
  396. }
  397. }
  398. } catch (h) {
  399. this.settings.debug
  400. && window.console
  401. && console.log("exception occured when checking element " + a.id
  402. + ", check the '" + f.method + "' method", h);
  403. throw h;
  404. }
  405. }
  406. if (!d) {
  407. this.objectLength(b) && this.successList.push(a);
  408. return true
  409. }
  410. },
  411. customMetaMessage : function(a, b) {
  412. if (c.metadata) {
  413. var d = this.settings.meta ? c(a).metadata()[this.settings.meta] : c(a).metadata();
  414. return d && d.messages && d.messages[b]
  415. }
  416. },
  417. customMessage : function(a, b) {
  418. var d = this.settings.messages[a];
  419. return d && (d.constructor == String ? d : d[b])
  420. },
  421. findDefined : function() {
  422. for ( var a = 0; a < arguments.length; a++)
  423. if (arguments[a] !== undefined)
  424. return arguments[a]
  425. },
  426. defaultMessage : function(a, b) {
  427. return this.findDefined(this.customMessage(a.name, b), this.customMetaMessage(a, b),
  428. !this.settings.ignoreTitle && a.title || undefined, c.validator.messages[b],
  429. "<strong>Warning: No message defined for " + a.name + "</strong>")
  430. },
  431. formatAndAdd : function(a, b) {
  432. var d = this.defaultMessage(a, b.method), e = /\$?\{(\d+)\}/g;
  433. if (typeof d == "function")
  434. d = d.call(this, b.parameters, a);
  435. else if (e.test(d))
  436. d = jQuery.format(d.replace(e, "{$1}"), b.parameters);
  437. this.errorList.push({
  438. message : d,
  439. element : a
  440. });
  441. this.errorMap[a.name] = d;
  442. this.submitted[a.name] = d
  443. },
  444. addWrapper : function(a) {
  445. if (this.settings.wrapper)
  446. a = a.add(a.parent(this.settings.wrapper));
  447. return a
  448. },
  449. defaultShowErrors : function() {
  450. for ( var a = 0; this.errorList[a]; a++) {
  451. var b = this.errorList[a];
  452. this.settings.highlight
  453. && this.settings.highlight.call(this, b.element, this.settings.errorClass,
  454. this.settings.validClass);
  455. this.showLabel(b.element, b.message)
  456. }
  457. if (this.errorList.length)
  458. this.toShow = this.toShow.add(this.containers);
  459. if (this.settings.success)
  460. for (a = 0; this.successList[a]; a++)
  461. this.showLabel(this.successList[a]);
  462. if (this.settings.unhighlight) {
  463. a = 0;
  464. for (b = this.validElements(); b[a]; a++)
  465. this.settings.unhighlight.call(this, b[a], this.settings.errorClass,
  466. this.settings.validClass)
  467. }
  468. this.toHide = this.toHide.not(this.toShow);
  469. this.hideErrors();
  470. this.addWrapper(this.toShow).show()
  471. },
  472. validElements : function() {
  473. return this.currentElements.not(this.invalidElements())
  474. },
  475. invalidElements : function() {
  476. return c(this.errorList).map(function() {
  477. return this.element
  478. })
  479. },
  480. showLabel : function(a, b) {
  481. var d = this.errorsFor(a);
  482. if (d.length) {
  483. d.removeClass().addClass(this.settings.errorClass);
  484. d.attr("generated") && d.html(b)
  485. } else {
  486. d = c("<" + this.settings.errorElement + "/>").attr({
  487. "for" : this.idOrName(a),
  488. generated : true
  489. }).addClass(this.settings.errorClass).html(b || "");
  490. if (this.settings.wrapper)
  491. d = d.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
  492. this.labelContainer.append(d).length
  493. || (this.settings.errorPlacement ? this.settings.errorPlacement(d, c(a))
  494. : d.insertAfter(a))
  495. }
  496. if (!b && this.settings.success) {
  497. d.text("");
  498. typeof this.settings.success == "string" ? d.addClass(this.settings.success)
  499. : this.settings.success(d)
  500. }
  501. this.toShow = this.toShow.add(d)
  502. },
  503. errorsFor : function(a) {
  504. var b = this.idOrName(a);
  505. return this.errors().filter(function() {
  506. return c(this).attr("for") == b
  507. })
  508. },
  509. idOrName : function(a) {
  510. return this.groups[a.name] || (this.checkable(a) ? a.name : a.id || a.name)
  511. },
  512. checkable : function(a) {
  513. return /radio|checkbox/i.test(a.type)
  514. },
  515. findByName : function(a) {
  516. var b = this.currentForm;
  517. return c(document.getElementsByName(a)).map(function(d, e) {
  518. return e.form == b && e.name == a && e || null
  519. })
  520. },
  521. getLength : function(a, b) {
  522. switch (b.nodeName.toLowerCase()) {
  523. case "select":
  524. return c("option:selected", b).length;
  525. case "input":
  526. if (this.checkable(b))
  527. return this.findByName(b.name).filter(":checked").length
  528. }
  529. return a.length
  530. },
  531. depend : function(a, b) {
  532. return this.dependTypes[typeof a] ? this.dependTypes[typeof a](a, b) : true
  533. },
  534. dependTypes : {
  535. "boolean" : function(a) {
  536. return a
  537. },
  538. string : function(a, b) {
  539. return !!c(a, b.form).length
  540. },
  541. "function" : function(a, b) {
  542. return a(b)
  543. }
  544. },
  545. optional : function(a) {
  546. return !c.validator.methods.required.call(this, c.trim(a.value), a)
  547. && "dependency-mismatch"
  548. },
  549. startRequest : function(a) {
  550. if (!this.pending[a.name]) {
  551. this.pendingRequest++;
  552. this.pending[a.name] = true
  553. }
  554. },
  555. stopRequest : function(a, b) {
  556. this.pendingRequest--;
  557. if (this.pendingRequest < 0)
  558. this.pendingRequest = 0;
  559. delete this.pending[a.name];
  560. if (b && this.pendingRequest == 0 && this.formSubmitted && this.form()) {
  561. c(this.currentForm).submit();
  562. this.formSubmitted = false
  563. } else if (!b && this.pendingRequest == 0 && this.formSubmitted) {
  564. c(this.currentForm).triggerHandler("invalid-form", [ this ]);
  565. this.formSubmitted = false
  566. }
  567. },
  568. previousValue : function(a) {
  569. return c.data(a, "previousValue") || c.data(a, "previousValue", {
  570. old : null,
  571. valid : true,
  572. message : this.defaultMessage(a, "remote")
  573. })
  574. }
  575. },
  576. classRuleSettings : {
  577. required : {
  578. required : true
  579. },
  580. email : {
  581. email : true
  582. },
  583. url : {
  584. url : true
  585. },
  586. date : {
  587. date : true
  588. },
  589. dateISO : {
  590. dateISO : true
  591. },
  592. dateDE : {
  593. dateDE : true
  594. },
  595. number : {
  596. number : true
  597. },
  598. numberDE : {
  599. numberDE : true
  600. },
  601. digits : {
  602. digits : true
  603. },
  604. creditcard : {
  605. creditcard : true
  606. }
  607. },
  608. addClassRules : function(a, b) {
  609. a.constructor == String ? this.classRuleSettings[a] = b : c.extend(this.classRuleSettings,
  610. a)
  611. },
  612. classRules : function(a) {
  613. var b = {};
  614. (a = c(a).attr("class"))
  615. && c.each(a.split(" "), function() {
  616. this in c.validator.classRuleSettings
  617. && c.extend(b, c.validator.classRuleSettings[this])
  618. });
  619. return b
  620. },
  621. attributeRules : function(a) {
  622. var b = {};
  623. a = c(a);
  624. for ( var d in c.validator.methods) {
  625. var e = a.attr(d);
  626. if (e)
  627. b[d] = e
  628. }
  629. b.maxlength && /-1|2147483647|524288/.test(b.maxlength) && delete b.maxlength;
  630. return b
  631. },
  632. metadataRules : function(a) {
  633. if (!c.metadata)
  634. return {};
  635. var b = c.data(a.form, "validator").settings.meta;
  636. return b ? c(a).metadata()[b] : c(a).metadata()
  637. },
  638. staticRules : function(a) {
  639. var b = {}, d = c.data(a.form, "validator");
  640. if (d.settings.rules)
  641. b = c.validator.normalizeRule(d.settings.rules[a.name]) || {};
  642. return b
  643. },
  644. normalizeRules : function(a, b) {
  645. c.each(a, function(d, e) {
  646. if (e === false)
  647. delete a[d];
  648. else if (e.param || e.depends) {
  649. var f = true;
  650. switch (typeof e.depends) {
  651. case "string":
  652. f = !!c(e.depends, b.form).length;
  653. break;
  654. case "function":
  655. f = e.depends.call(b, b)
  656. }
  657. if (f)
  658. a[d] = e.param !== undefined ? e.param : true;
  659. else
  660. delete a[d]
  661. }
  662. });
  663. c.each(a, function(d, e) {
  664. a[d] = c.isFunction(e) ? e(b) : e
  665. });
  666. c.each([ "minlength", "maxlength", "min", "max" ], function() {
  667. if (a[this])
  668. a[this] = Number(a[this])
  669. });
  670. c.each([ "rangelength", "range" ], function() {
  671. if (a[this])
  672. a[this] = [ Number(a[this][0]), Number(a[this][1]) ]
  673. });
  674. if (c.validator.autoCreateRanges) {
  675. if (a.min && a.max) {
  676. a.range = [ a.min, a.max ];
  677. delete a.min;
  678. delete a.max
  679. }
  680. if (a.minlength && a.maxlength) {
  681. a.rangelength = [ a.minlength, a.maxlength ];
  682. delete a.minlength;
  683. delete a.maxlength
  684. }
  685. }
  686. a.messages && delete a.messages;
  687. return a
  688. },
  689. normalizeRule : function(a) {
  690. if (typeof a == "string") {
  691. var b = {};
  692. c.each(a.split(/\s/), function() {
  693. b[this] = true
  694. });
  695. a = b
  696. }
  697. return a
  698. },
  699. addMethod : function(a, b, d) {
  700. c.validator.methods[a] = b;
  701. c.validator.messages[a] = d != undefined ? d : c.validator.messages[a];
  702. b.length < 3 && c.validator.addClassRules(a, c.validator.normalizeRule(a))
  703. },
  704. methods : {
  705. required : function(a, b, d) {
  706. if (!this.depend(d, b))
  707. return "dependency-mismatch";
  708. switch (b.nodeName.toLowerCase()) {
  709. case "select":
  710. return (a = c(b).val()) && a.length > 0;
  711. case "input":
  712. if (this.checkable(b))
  713. return this.getLength(a, b) > 0;
  714. default:
  715. return c.trim(a).length > 0
  716. }
  717. },
  718. remote : function(a, b, d) {
  719. if (this.optional(b))
  720. return "dependency-mismatch";
  721. var e = this.previousValue(b);
  722. this.settings.messages[b.name] || (this.settings.messages[b.name] = {});
  723. e.originalMessage = this.settings.messages[b.name].remote;
  724. this.settings.messages[b.name].remote = e.message;
  725. d = typeof d == "string" && {
  726. url : d
  727. } || d;
  728. if (this.pending[b.name])
  729. return "pending";
  730. if (e.old === a)
  731. return e.valid;
  732. e.old = a;
  733. var f = this;
  734. this.startRequest(b);
  735. var g = {};
  736. g[b.name] = a;
  737. c.ajax(c.extend(true, {
  738. url : d,
  739. mode : "abort",
  740. port : "validate" + b.name,
  741. dataType : "json",
  742. data : g,
  743. success : function(h) {
  744. f.settings.messages[b.name].remote = e.originalMessage;
  745. var j = h === true;
  746. if (j) {
  747. var i = f.formSubmitted;
  748. f.prepareElement(b);
  749. f.formSubmitted = i;
  750. f.successList.push(b);
  751. f.showErrors()
  752. } else {
  753. i = {};
  754. h = h || f.defaultMessage(b, "remote");
  755. i[b.name] = e.message = c.isFunction(h) ? h(a) : h;
  756. f.showErrors(i)
  757. }
  758. e.valid = j;
  759. f.stopRequest(b, j)
  760. }
  761. }, d));
  762. return "pending"
  763. },
  764. minlength : function(a, b, d) {
  765. return this.optional(b) || this.getLength(c.trim(a), b) >= d
  766. },
  767. maxlength : function(a, b, d) {
  768. return this.optional(b) || this.getLength(c.trim(a), b) <= d
  769. },
  770. rangelength : function(a, b, d) {
  771. a = this.getLength(c.trim(a), b);
  772. return this.optional(b) || a >= d[0] && a <= d[1]
  773. },
  774. min : function(a, b, d) {
  775. return this.optional(b) || a >= d
  776. },
  777. max : function(a, b, d) {
  778. return this.optional(b) || a <= d
  779. },
  780. range : function(a, b, d) {
  781. return this.optional(b) || a >= d[0] && a <= d[1]
  782. },
  783. email : function(a, b) {
  784. return this.optional(b)
  785. || /^((([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
  786. .test(a)
  787. },
  788. url : function(a, b) {
  789. return this.optional(b)
  790. || /^(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
  791. .test(a)
  792. },
  793. date : function(a, b) {
  794. return this.optional(b) || !/Invalid|NaN/.test(new Date(a))
  795. },
  796. dateISO : function(a, b) {
  797. return this.optional(b) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(a)
  798. },
  799. number : function(a, b) {
  800. return this.optional(b) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(a)
  801. },
  802. digits : function(a, b) {
  803. return this.optional(b) || /^\d+$/.test(a)
  804. },
  805. creditcard : function(a, b) {
  806. if (this.optional(b))
  807. return "dependency-mismatch";
  808. if (/[^0-9-]+/.test(a))
  809. return false;
  810. var d = 0, e = 0, f = false;
  811. a = a.replace(/\D/g, "");
  812. for ( var g = a.length - 1; g >= 0; g--) {
  813. e = a.charAt(g);
  814. e = parseInt(e, 10);
  815. if (f)
  816. if ((e *= 2) > 9)
  817. e -= 9;
  818. d += e;
  819. f = !f
  820. }
  821. return d % 10 == 0
  822. },
  823. accept : function(a, b, d) {
  824. d = typeof d == "string" ? d.replace(/,/g, "|") : "png|jpe?g|gif";
  825. return this.optional(b) || a.match(RegExp(".(" + d + ")$", "i"))
  826. },
  827. equalTo : function(a, b, d) {
  828. d = c(d).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
  829. c(b).valid()
  830. });
  831. return a == d.val()
  832. }
  833. }
  834. });
  835. c.format = c.validator.format
  836. })(jQuery);
  837. (function(c) {
  838. var a = {};
  839. if (c.ajaxPrefilter)
  840. c.ajaxPrefilter(function(d, e, f) {
  841. e = d.port;
  842. if (d.mode == "abort") {
  843. a[e] && a[e].abort();
  844. a[e] = f
  845. }
  846. });
  847. else {
  848. var b = c.ajax;
  849. c.ajax = function(d) {
  850. var e = ("port" in d ? d : c.ajaxSettings).port;
  851. if (("mode" in d ? d : c.ajaxSettings).mode == "abort") {
  852. a[e] && a[e].abort();
  853. return a[e] = b.apply(this, arguments)
  854. }
  855. return b.apply(this, arguments)
  856. }
  857. }
  858. })(jQuery);
  859. (function(c) {
  860. !jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener && c.each({
  861. focus : "focusin",
  862. blur : "focusout"
  863. }, function(a, b) {
  864. function d(e) {
  865. e = c.event.fix(e);
  866. e.type = b;
  867. return c.event.handle.call(this, e)
  868. }
  869. c.event.special[b] = {
  870. setup : function() {
  871. this.addEventListener(a, d, true)
  872. },
  873. teardown : function() {
  874. this.removeEventListener(a, d, true)
  875. },
  876. handler : function(e) {
  877. arguments[0] = c.event.fix(e);
  878. arguments[0].type = b;
  879. return c.event.handle.apply(this, arguments)
  880. }
  881. }
  882. });
  883. c.extend(c.fn, {
  884. validateDelegate : function(a, b, d) {
  885. return this.bind(b, function(e) {
  886. var f = c(e.target);
  887. if (f.is(a))
  888. return d.apply(f, arguments)
  889. })
  890. }
  891. })
  892. })(jQuery);