check.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. function CheckNull(strElem,strName)
  2. {
  3. if(document.getElementById(strElem).value == "")
  4. {
  5. window.alert(strName + " 为必填项");
  6. document.getElementById(strElem).focus();
  7. return false;
  8. }
  9. return true;
  10. }
  11. function CheckMustNum(strElem,strName)
  12. {
  13. if( document.getElementById(strElem).value == "" || isNaN(document.getElementById(strElem).value))
  14. {
  15. window.alert(strName + " 为必填项且必须是数值型");
  16. document.getElementById(strElem).focus();
  17. return false;
  18. }
  19. return true;
  20. }
  21. function CheckNum(strElem,strName)
  22. {
  23. if(isNaN(document.getElementById(strElem).value))
  24. {
  25. window.alert(strName + " 必须是数值型");
  26. document.getElementById(strElem).focus();
  27. return false;
  28. }
  29. return true;
  30. }
  31. function CheckNumber(strElem,strName)
  32. {
  33. var str = document.getElementById(strElem).value ;
  34. for(var i=0;i<str.length;i++)
  35. {
  36. var strTmp = str.charAt(i) ;
  37. if(strTmp < "0" || strTmp > "9")
  38. {
  39. window.alert(strName + " 必须是整数");
  40. document.getElementById(strElem).focus();
  41. return false;
  42. }
  43. }
  44. return true ;
  45. }
  46. //只能输入中文字
  47. function CheckChinese(strElem,strName)
  48. {
  49. var str = document.getElementById(strElem).value ;
  50. for(var i=0;i<str.length;i++)
  51. {
  52. var strTmp = str.charAt(i) ;
  53. if(document.getElementById(strElem).value.indexOf('0123456789qwertyuiopasdfghjklzxcvbnm') != -1)
  54. {
  55. window.alert(strName + " 只能填写中文");
  56. document.getElementById(strElem).focus();
  57. return false;
  58. }
  59. }
  60. return true ;
  61. }
  62. //只能输入中文和英文
  63. function CheckEC(strElem,strName)
  64. {
  65. var str = document.getElementById(strElem).value ;
  66. for(var i=0;i<str.length;i++)
  67. {
  68. var strTmp = str.charAt(i) ;
  69. if(document.getElementById(strElem).value.indexOf('0123456789!@#$%^&*()~`,./;') != -1)
  70. {
  71. window.alert(strName + " 只能填写中文和英文");
  72. document.getElementById(strElem).focus();
  73. return false;
  74. }
  75. }
  76. return true ;
  77. }
  78. function CheckEmail(strElem,strName)
  79. {
  80. if(document.getElementById(strElem).value.indexOf('@') == -1)
  81. {
  82. window.alert("请输入正确的 " + strName);
  83. document.getElementById(strElem).focus();
  84. return false;
  85. }
  86. return true;
  87. }
  88. function CheckMustDate(strElem,strName)
  89. {
  90. if(CommCheckDate(document.getElementById(strElem).value))
  91. {
  92. return true;
  93. }
  94. else
  95. {
  96. window.alert(strName + " 是必填项且为日期型,例:1900-01-01");
  97. document.getElementById(strElem).focus();
  98. return false
  99. }
  100. }
  101. function CheckDate(strElem,strName)
  102. {
  103. if(document.getElementById(strElem).value == "")
  104. {
  105. return true;
  106. }
  107. if(CommCheckDate(document.getElementById(strElem).value))
  108. {
  109. return true;
  110. }
  111. else
  112. {
  113. window.alert(strName + " 必须是日期型,例:1900-01-01");
  114. document.getElementById(strElem).focus();
  115. return false
  116. }
  117. }
  118. function CommCheckDate(strValue)
  119. {
  120. var objRegExp = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/
  121. if(!objRegExp.test(strValue))
  122. {
  123. return false;
  124. }
  125. //
  126. var arrayDate = strValue.split(RegExp.$1);
  127. var intDay = parseInt(arrayDate[2],10);
  128. var intYear = parseInt(arrayDate[0],10);
  129. var intMonth = parseInt(arrayDate[1],10);
  130. switch(intMonth)
  131. {
  132. case 1:
  133. if(intDay <= 31 && intDay >0)
  134. {
  135. return true;
  136. }
  137. case 3:
  138. if(intDay <= 31 && intDay >0)
  139. {
  140. return true;
  141. }
  142. case 5:
  143. if(intDay <= 31 && intDay >0)
  144. {
  145. return true;
  146. }
  147. case 7:
  148. if(intDay <= 31 && intDay >0)
  149. {
  150. return true;
  151. }
  152. case 8:
  153. if(intDay <= 31 && intDay >0)
  154. {
  155. return true;
  156. }
  157. case 10:
  158. if(intDay <= 31 && intDay >0)
  159. {
  160. return true;
  161. }
  162. case 12:
  163. if(intDay <= 31 && intDay >0)
  164. {
  165. return true;
  166. }
  167. case 4:
  168. if(intDay <=30 && intDay >0)
  169. {
  170. return true;
  171. }
  172. case 6:
  173. if(intDay <=30 && intDay >0)
  174. {
  175. return true;
  176. }
  177. case 9:
  178. if(intDay <=30 && intDay >0)
  179. {
  180. return true;
  181. }
  182. case 11:
  183. if(intDay <=30 && intDay >0)
  184. {
  185. return true;
  186. }
  187. case 2:
  188. var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
  189. if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay >0)
  190. {
  191. return true;
  192. }
  193. default:
  194. return false;
  195. }
  196. return false;
  197. }
  198. function CompareDate(SmallDate,BigDate)
  199. {
  200. var intSmallYearLen = SmallDate.indexOf('-');
  201. var intBigYearLen = BigDate.indexOf('-');
  202. if(intSmallYearLen==-1 || intBigYearLen==-1)
  203. {
  204. return true;
  205. }
  206. var strSmallYear = parseInt(SmallDate.substring(0,intSmallYearLen));
  207. var strBigYear = parseInt(BigDate.substring(0,intBigYearLen));
  208. if(strSmallYear > strBigYear)
  209. {
  210. return false;
  211. }
  212. else if(strSmallYear < strBigYear)
  213. {
  214. return true;
  215. }
  216. else if(strSmallYear == strBigYear)
  217. {
  218. var intSmallMonthLen = SmallDate.indexOf('-',5);
  219. var intBigMonthLen = BigDate.indexOf('-',5);
  220. var strSmallMonth = parseInt(SmallDate.substring(intSmallYearLen+1,intSmallMonthLen));
  221. var strBigMonth = parseInt(BigDate.substring(intBigYearLen+1,intBigMonthLen));
  222. if(strSmallMonth > strBigMonth)
  223. {
  224. return false;
  225. }
  226. else if(strSmallMonth < strBigMonth)
  227. {
  228. return true;
  229. }
  230. else if(strSmallMonth == strBigMonth)
  231. {
  232. if(SmallDate.indexOf(':')>0)
  233. {
  234. SmallDate = SmallDate.substring(0,SmallDate.length-8);
  235. }
  236. if(BigDate.indexOf(':')>0)
  237. {
  238. BigDate = BigDate.substring(0,BigDate.length-8);
  239. }
  240. var intSmallDay = SmallDate.lastIndexOf('-')+1;
  241. var intBigDay = BigDate.lastIndexOf('-')+1;
  242. var strSmallDay = parseInt(SmallDate.substring(intSmallDay,SmallDate.length));
  243. var strBigDay = parseInt(BigDate.substring(intBigDay,BigDate.length));
  244. if(strSmallDay > strBigDay || strSmallDay == strBigDay)
  245. {
  246. return false;
  247. }
  248. else
  249. {
  250. return true;
  251. }
  252. }
  253. }
  254. }