en.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*********************************
  2. * Themes, rules, and i18n support
  3. * Locale: English
  4. *********************************/
  5. (function(factory) {
  6. typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
  7. typeof define === 'function' && define.amd ? define(['jquery'], factory) :
  8. factory(jQuery);
  9. }(function($) {
  10. /* Global configuration
  11. */
  12. $.validator.config({
  13. //stopOnError: true,
  14. //focusCleanup: true,
  15. //theme: 'yellow_right',
  16. //timely: 2,
  17. // Custom rules
  18. rules: {
  19. digits: [/^\d+$/, "Please enter only digits."]
  20. ,letters: [/^[a-z]+$/i, "Please enter only letters."]
  21. ,date: [/^\d{4}-\d{2}-\d{2}$/, "Please enter a valid date, format: yyyy-mm-dd"]
  22. ,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "Please enter a valid time, between 00:00 and 23:59"]
  23. ,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "Please enter a valid email address."]
  24. ,url: [/^(https?|s?ftp):\/\/\S+$/i, "Please enter a valid URL."]
  25. ,accept: function (element, params){
  26. if (!params) return true;
  27. var ext = params[0],
  28. value = $(element).val();
  29. return (ext === '*') ||
  30. (new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
  31. this.renderMsg("Only accept {1} file extension.", ext.replace(/\|/g, ', '));
  32. }
  33. },
  34. // Default error messages
  35. messages: {
  36. 0: "This field",
  37. fallback: "{0} is not valid.",
  38. loading: "Validating...",
  39. error: "Network Error.",
  40. timeout: "Request timed out.",
  41. required: "{0} is required.",
  42. remote: "Please try another name.",
  43. integer: {
  44. '*': "Please enter an integer.",
  45. '+': "Please enter a positive integer.",
  46. '+0': "Please enter a positive integer or 0.",
  47. '-': "Please enter a negative integer.",
  48. '-0': "Please enter a negative integer or 0."
  49. },
  50. match: {
  51. eq: "{0} must be equal to {1}.",
  52. neq: "{0} must be not equal to {1}.",
  53. lt: "{0} must be less than {1}.",
  54. gt: "{0} must be greater than {1}.",
  55. lte: "{0} must be less than or equal to {1}.",
  56. gte: "{0} must be greater than or equal to {1}."
  57. },
  58. range: {
  59. rg: "Please enter a number between {1} and {2}.",
  60. gte: "Please enter a number greater than or equal to {1}.",
  61. lte: "Please enter a number less than or equal to {1}.",
  62. gtlt: "Please fill in the number of {1} to {2}.",
  63. gt: "Please enter a number greater than {1}.",
  64. lt: "Please enter a number less than {1}."
  65. },
  66. checked: {
  67. eq: "Please check {1} items.",
  68. rg: "Please check between {1} and {2} items.",
  69. gte: "Please check at least {1} items.",
  70. lte: "Please check no more than {1} items."
  71. },
  72. length: {
  73. eq: "Please enter {1} characters.",
  74. rg: "Please enter a value between {1} and {2} characters long.",
  75. gte: "Please enter at least {1} characters.",
  76. lte: "Please enter no more than {1} characters.",
  77. eq_2: "",
  78. rg_2: "",
  79. gte_2: "",
  80. lte_2: ""
  81. }
  82. }
  83. });
  84. /* Themes
  85. */
  86. var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
  87. $.validator.setTheme({
  88. 'simple_right': {
  89. formClass: 'n-simple',
  90. msgClass: 'n-right'
  91. },
  92. 'simple_bottom': {
  93. formClass: 'n-simple',
  94. msgClass: 'n-bottom'
  95. },
  96. 'yellow_top': {
  97. formClass: 'n-yellow',
  98. msgClass: 'n-top',
  99. msgArrow: TPL_ARROW
  100. },
  101. 'yellow_right': {
  102. formClass: 'n-yellow',
  103. msgClass: 'n-right',
  104. msgArrow: TPL_ARROW
  105. },
  106. 'yellow_right_effect': {
  107. formClass: 'n-yellow',
  108. msgClass: 'n-right',
  109. msgArrow: TPL_ARROW,
  110. msgShow: function($msgbox, type){
  111. var $el = $msgbox.children();
  112. if ($el.is(':animated')) return;
  113. if (type === 'error') {
  114. $el.css({left: '20px', opacity: 0})
  115. .delay(100).show().stop()
  116. .animate({left: '-4px', opacity: 1}, 150)
  117. .animate({left: '3px'}, 80)
  118. .animate({left: 0}, 80);
  119. } else {
  120. $el.css({left: 0, opacity: 1}).fadeIn(200);
  121. }
  122. },
  123. msgHide: function($msgbox, type){
  124. var $el = $msgbox.children();
  125. $el.stop().delay(100).show()
  126. .animate({left: '20px', opacity: 0}, 300, function(){
  127. $msgbox.hide();
  128. });
  129. }
  130. }
  131. });
  132. }));