//函式名:chksafe
//功能介紹:檢查是否含有"'",'//',"/"
//引數說明:要檢查的字串
//返回值:0:是 1:不是
function chksafe(a)}}
return 0;
}//opt1 小數 opt2 負數
//當opt2為1時檢查num是否是負數
//當opt1為1時檢查num是否是小數
//返回1是正確的,0是錯誤的
function chknbr(num,opt1,opt2)
//當最後一位為.時出錯
if (num.charat(i-1)=='.')
for (j=0;j1)
if (num.charat(j)<'0' || num.charat(j)>'9' )}}
return 1;
}//函式名:chkdate
//功能介紹:檢查是否為日期
//引數說明:要檢查的字串
//返回值:0:不是日期 1:是日期
function chkdate(datestr)
if ((status==0) && (datestr.charat(i)!='-'))
if ((status==1) && (datestr.charat(i)!='-'))
if ((status==2) && (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))
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
if (!((year % 4)==0) && (month==2) && (day==29))
if ((month<=7) && ((month % 2)==0) && (day>=31))
if ((month>=8) && ((month % 2)==1) && (day>=31))
if ((month==2) && (day==30))
return 1;
}//函式名:fucpwdchk
//功能介紹:檢查是否含有非數字或字母
//引數說明:要檢查的字串
//返回值:0:含有 1:全部為數字或字母
function fucpwdchk(str)
}if (strsource.indexof(ch)==-1)
else }
function jtrim(str)
while (str.charat(str.length-1)==" ")
return(str);
}//函式名:fucchecknum
//功能介紹:檢查是否為數字
//引數說明:要檢查的數字
//返回值:1為是數字,0為不是數字
function fucchecknum(num)
return sum;
}
js 常用的校驗方法
身份證校驗 function identitycodevalid code let pass true 驗證身份證格式 6個地區編碼,8位出生日期,3位順序號,1位校驗位 if code d 18 19 20 d 0 1 9 1 012 0 1 9 12 d 3 01 d d x i test co...
常用校驗方法
是否為空校驗 function isempty s var lll trim s if lll null lll.length 0 return true else return false 刪除字串左邊的空格 function ltrim str if str.length 0 return st...
優化表單資料的JS校驗
在平常的web開發中,我經常需要在客戶端對表單的資料進行驗證。比如,我們驗證表單輸入的內容不為空 1 根據以往的經驗,我們會寫出如下的js驗證 但是,現在我有乙個業務追求 我要在頁面取得的表單資料有很多,比如有十幾二十項資料吧,那麼我們要在js 中重複的寫一部分 這樣就將頁面的 拉得很長,以至於 很...