// STRING FUNCTIONS function trim ( str ) { // Immediately return if no trimming is needed if( (str.charAt(0) != ' ') && (str.charAt(str.length-1) != ' ') ) { return str; } // Trim leading spaces while( str.charAt(0) == ' ' ) { str = '' + str.substring(1,str.length); } // Trim trailing spaces while( str.charAt(str.length-1) == ' ' ) { str = '' + str.substring(0,str.length-1); } return str; } //检查输入是否为空 function chkNull (str) { if (trim(str) == '') { return false; } else { return true; } } //函数名:checkInputNull //功能介绍:检查input对象的值是否为空,只能是有value属性的对象 //参数说明:obj 要检查的input对象 //参数说明:prompt 错误提示 //返回值:false:非空 true:空 function checkInputNull(obj,prompt){ if(trim(obj.value) == ""){ alert(prompt); obj.focus(); return true; } return false; } //函数名:chkdatetime //功能介绍:检查是否为时间格式 //参数说明:datetimestr 要检查的字符串 //参数说明:dateseparator 要检查的日期分割符 //参数说明:timeseparator 要检查的时间分割符 //返回值:false:不是时间 true:是时间 function chkdatetime (datetimestr,dateseparator,timeseparator) { if (datetimestr == "") { return false; } var tmpdate=""; var tmptime=""; var status; status=0; for (kk=0;kk1) { //alert("Invalid format of date!"); return false; } if ((status==0) && (datetimestr.charAt(kk)!=' ')) { tmpdate=tmpdate+datetimestr.charAt(kk) } if ((status==1) && (datetimestr.charAt(kk)!=' ')) { tmptime=tmptime+datetimestr.charAt(kk) } } if (chkdate(tmpdate,dateseparator)) { //now check time status = 0; if (tmptime == "") { return false; } var tmphour = ""; var tmpminute = ""; for (kk=0;kk1) { //alert("Invalid format of date!"); return false; } if ((status==0) && (tmptime.charAt(kk)!=timeseparator)) { tmphour=tmphour+tmptime.charAt(kk) } if ((status==1) && (tmptime.charAt(kk)!=timeseparator)) { tmpminute=tmpminute+tmptime.charAt(kk) } } if (!((tmphour>=0) && (tmphour<24))) { return false; } if (!((tmpminute>=0) && (tmpminute<60))) { return false; } return true; } return false; } //函数名:chkdate //功能介绍:检查是否为日期 //参数说明:datestr 要检查的字符串 //参数说明:separator 要检查的日期分割符 //返回值:false:不是日期 true:是日期 function chkdate(datestr,separator) { var lthdatestr if (datestr != "") lthdatestr= datestr.length ; else lthdatestr=0; var tmpy=""; var tmpm=""; var tmpd=""; //var datestr; var status; status=0; if ( lthdatestr== 0) return false; for (kk=0;kk2) { //alert("Invalid format of date!"); return false; } if ((status==0) && (datestr.charAt(kk)!=separator)) { tmpy=tmpy+datestr.charAt(kk) } if ((status==1) && (datestr.charAt(kk)!=separator)) { tmpm=tmpm+datestr.charAt(kk) } if ((status==2) && (datestr.charAt(kk)!=separator)) { tmpd=tmpd+datestr.charAt(kk) } } year=new String (tmpy); month=new String (tmpm); day=new String (tmpd) //tempdate= new String (year+month+day); //alert(tempdate); if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2)) { //alert("Invalid format of date!"); return false; } if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) ) { //alert ("Invalid month or day!"); return false; } if (!((year % 4)==0) && (month==2) && (day==29)) { //alert ("This is not a leap year!"); return false; } if ((month<=7) && ((month % 2)==0) && (day>=31)) { //alert ("This month is a small month!"); return false; } if ((month>=8) && ((month % 2)==1) && (day>=31)) { //alert ("This month is a small month!"); return false; } if ((month==2) && (day==30)) { //alert("The Febryary never has this day!"); return false; } return true; } //函数名:chknum //功能介绍:检查是否为数值 //参数说明:要检查的字符串 //返回值:false:不是数值 true:是数值 function chknum(num){ numstring="0123456789." for(iii=0;iii