js 幾種常用的表單輸入判斷
來(lái)源:中信時(shí)代網(wǎng)絡(luò)科技 | 作者:admin | 時(shí)間:2013-03-25 | 點(diǎn)擊量:2755
//函數(shù)名:chksafe //功能介紹:檢查是否含有"",\\,"/" //參數(shù)說(shuō)明:要檢查的字符串 //返回值:0:是 1:不是 function chksafe(a) { return 1; /* fibdn = new Array ("" ,"\\", "、", ",", ";", "/"); i=fibdn.length; j=a.length; for (ii=0;ii
1) { if ((i-temp) > 3){ if ((i-tempd)>0){ return 1; } } } return 0; }//opt1 小數(shù) opt2 負(fù)數(shù) //當(dāng)opt2為1時(shí)檢查num是否是負(fù)數(shù) //當(dāng)opt1為1時(shí)檢查num是否是小數(shù) //返回1是正確的,0是錯(cuò)誤的 function chknbr(num,opt1,opt2) { var i=num.length; var staus; //staus用于記錄.的個(gè)數(shù) status=0; if ((opt2!=1) && (num.charAt(0)==-)) { //alert("You have enter a invalid number."); return 0; } //當(dāng)最后一位為.時(shí)出錯(cuò) if (num.charAt(i-1)==.) { //alert("You have enter a invalid number."); return 0; } for (j=0;j1) { //alert("You have enter a invalid number."); return 0; } if (num.charAt(j)<0 || num.charAt(j)>9 ) { if (((opt1==0) || (num.charAt(j)!=.)) && (j!=0)) { //alert("You have enter a invalid number."); return 0; } } } return 1; } //函數(shù)名:chkdate //功能介紹:檢查是否為日期 //參數(shù)說(shuō)明:要檢查的字符串 //返回值:0:不是日期 1:是日期 function chkdate(datestr) { 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 0 for (i=0;i2) { //alert("Invalid format of date!"); return 0; } if ((status==0) && (datestr.charAt(i)!=-)) { tmpy=tmpy+datestr.charAt(i) } if ((status==1) && (datestr.charAt(i)!=-)) { tmpm=tmpm+datestr.charAt(i) } if ((status==2) && (datestr.charAt(i)!=-)) { tmpd=tmpd+datestr.charAt(i) } } 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 0; } if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) ) { //alert ("Invalid month or day!"); return 0; } if (!((year % 4)==0) && (month==2) && (day==29)) { //alert ("This is not a leap year!"); return 0; } if ((month<=7) && ((month % 2)==0) && (day>=31)) { //alert ("This month is a small month!"); return 0; } if ((month>=8) && ((month % 2)==1) && (day>=31)) { //alert ("This month is a small month!"); return 0; } if ((month==2) && (day==30)) { //alert("The Febryary never has this day!"); return 0; } return 1; } //函數(shù)名:fucPWDchk //功能介紹:檢查是否含有非數(shù)字或字母 //參數(shù)說(shuō)明:要檢查的字符串 //返回值:0:含有 1:全部為數(shù)字或字母 function fucPWDchk(str) { var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; var ch; var i; var temp; for (i=0;i<=(str.length-1);i++) { ch = str.charAt(i); temp = strSource.indexOf(ch); if (temp==-1) { return 0; } } if (strSource.indexOf(ch)==-1) { return 0; } else { return 1; } } function jtrim(str) { while (str.charAt(0)==" ") {str=str.substr(1);} while (str.charAt(str.length-1)==" ") {str=str.substr(0,str.length-1);} return(str); } //函數(shù)名:fucCheckNUM //功能介紹:檢查是否為數(shù)字 //參數(shù)說(shuō)明:要檢查的數(shù)字 //返回值:1為是數(shù)字,0為不是數(shù)字 function fucCheckNUM(NUM) { var i,j,strTemp; strTemp="0123456789"; if ( NUM.length== 0) return 0 for (i=0;i=0) && (strTemp.charCodeAt(i)<=255)) sum=sum+1; else sum=sum+2; } return sum; }