checkinput.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. function checkEmpty(aControlName, aTipMsg) {
  2. var aObj = document.forms[0].elements[aControlName];
  3. if (aObj.value == "") {
  4. alert(aTipMsg + "����Ϊ�գ�");
  5. aObj.focus();
  6. return false;
  7. }
  8. return true;
  9. }
  10. function checkRadioCheckboxEmpty(aControlName, aTipMsg) {
  11. var aObj = document.getElementsByName(aControlName);
  12. var count = aObj.length;
  13. var aEmpty = true;
  14. for (i = 0; i < count; i++) {
  15. if (aObj[i].checked == true) {
  16. aEmpty = false;
  17. break;
  18. }
  19. }
  20. if (aEmpty == true) {
  21. alert(aTipMsg + "����Ϊ�գ�");
  22. aObj[0].focus();
  23. return false;
  24. }
  25. return true;
  26. }
  27. function checkReferenceEmpty(aControlName, aTipMsg) {
  28. var aObj = document.forms[0].elements[aControlName];
  29. if (aObj.value == "") {
  30. alert(aTipMsg + "����Ϊ�գ�");
  31. return false;
  32. }
  33. return true;
  34. }
  35. function checkRegx(aControlName, aTipMsg, aRegexValue) {
  36. var aObj = document.forms[0].elements[aControlName];
  37. if (aObj.value == "")
  38. return true;
  39. var regex = new RegExp(aRegexValue);
  40. if (!regex.test(aObj.value)) {
  41. alert(aTipMsg + "��ʽ����ȷ��");
  42. aObj.focus();
  43. return false;
  44. }
  45. return true;
  46. }
  47. function isNumeric(aControlName, aTipMsg, aRegexValue) {
  48. var aObj = document.forms[0].elements[aControlName];
  49. if (aObj.value == "")
  50. return true;
  51. var regex = new RegExp(aRegexValue);
  52. if (!regex.test(aObj.value)) {
  53. alert(aTipMsg + "������ֵ��");
  54. aObj.focus();
  55. return false;
  56. }
  57. return true;
  58. }
  59. function checkRange(aControlName, aTipMsg, maxValue, minValue) {
  60. var aObj = document.forms[0].elements[aControlName];
  61. if (aObj.value == "")
  62. return true;
  63. var aCompareValue = parseFloat(aObj.value);
  64. if (maxValue != "" && aCompareValue > maxValue) {
  65. alert(aTipMsg + "���ܴ��� " + maxValue + " ��");
  66. aObj.focus();
  67. return false;
  68. }
  69. if (minValue != "" && aCompareValue < minValue) {
  70. alert(aTipMsg + "������ " + minValue + " ��");
  71. aObj.focus();
  72. return false;
  73. }
  74. return true;
  75. }
  76. function checkMaxLength(aControlName, aTipMsg, maxLength) {
  77. var aObj = document.forms[0].elements[aControlName];
  78. if (aObj.value.length > maxLength) {
  79. alert(aTipMsg + "��ݳ��Ȳ��ܴ��� " + maxLength + " λ��");
  80. aObj.focus();
  81. return false;
  82. }
  83. return true;
  84. }
  85. function validateAll(aControlName, aTipMsg, dataType, theMaxLength,
  86. theScaleSize) {
  87. if (dataType == "number") {
  88. if (isNumeric(aControlName, aTipMsg, "^(-|\\+)?\\d+(\\.\\d+)?$"))
  89. return true;
  90. else {
  91. document.forms[0].elements[aControlName].focus;
  92. return false;
  93. }
  94. } else if (dataType == "string") {
  95. if (checkMaxLength(aControlName, aTipMsg, theMaxLength))
  96. return true;
  97. else {
  98. document.forms[0].elements[aControlName].focus;
  99. return false;
  100. }
  101. }
  102. return true;
  103. }