jquery.validate.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;
  2. ( function($) {
  3. $.fn.checkForm = function(arg) {
  4. var count = 0;
  5. //
  6. for ( var i = 0; i < arg.length; i++) {
  7. id_ = arg[i].id;
  8. format_ = arg[i].format;
  9. type_ = arg[i].type;
  10. errinfo = arg[i].errinfo;
  11. if (!checkItem(id_, format_, type_))
  12. count++;
  13. }
  14. if (count > 0) {
  15. return false;
  16. } else {
  17. return true;
  18. }
  19. }
  20. function checkItem(id, dataType, type) {
  21. type = "text";
  22. var result = true;
  23. value = "";
  24. var $o = $("#" + id);
  25. value = $("#" + id).val();
  26. switch (Number(dataType)) {
  27. case 1:
  28. if (!ChkUtil.isDigit(value)) {
  29. result = false;
  30. error(id, "��������ָ�ʽ");
  31. } else {
  32. sucess(id);
  33. }
  34. break;
  35. case 2:
  36. if (!ChkUtil.isDate(value)) {
  37. result = false;
  38. error(id, "��������ڸ�ʽ");
  39. } else {
  40. sucess(id);
  41. }
  42. break;
  43. case 3:
  44. if (!ChkUtil.isEmail(value)) {
  45. result = false;
  46. error(id, "������ʼ���ʽ");
  47. } else {
  48. sucess(id);
  49. }
  50. break;
  51. case 4:
  52. if (!ChkUtil.isZipCode(value)) {
  53. result = false;
  54. error(id, "��������������ʽ");
  55. } else {
  56. sucess(id);
  57. }
  58. break;
  59. case 5:
  60. if (ChkUtil.isNull(value)) {
  61. result = false;
  62. error(id, "����");
  63. } else {
  64. sucess(id);
  65. }
  66. break;
  67. case 6:
  68. if (!ChkUtil.isMobile(value)) {
  69. result = false;
  70. error(id, "������ֻ�����ʽ");
  71. } else {
  72. sucess(id);
  73. }
  74. break;
  75. case 7:
  76. if (!ChkUtil.isPhone(value)) {
  77. result = false;
  78. error(id, "����ϵ绰�����ʽ");
  79. } else {
  80. sucess(id);
  81. }
  82. break;
  83. case 8:
  84. if (!ChkUtil.isString6_20(value)) {
  85. result = false;
  86. error(id, "����Ϊ6-20");
  87. } else {
  88. sucess(id);
  89. }
  90. break;
  91. default:
  92. }
  93. return result;
  94. }
  95. function error(id, info) {
  96. var $o = $("#" + id);
  97. $o.next().remove();
  98. $o.after($("<em class='error'>" + info + "</em>"));
  99. }
  100. function sucess(id) {
  101. var $o = $("#" + id);
  102. $o.next().remove();
  103. $o.after($("<em class='success'>&nbsp;</em>"));
  104. }
  105. })(jQuery);