js驗證總結

2021-09-01 10:53:08 字數 2096 閱讀 5332

js檔案

//測試輸入框的值是否整數

function checknum(inputobj)

//測試輸入框的值的個數

function checklength(inputobj, maxlength)

//將字串的首尾空格全部去掉

string.prototype.trim = function()

//測試輸入框是否空值.value

function checkinputvalueisempty(inputobj)

else

}//判斷乙個控制項的值是否為空

function checkvalueisempty(inputvalue)

else

}//驗證最大長度指定的正小數,inputobj為input物件,beforelength為小數點前面的位數個數,afterlength為小數點後面的位數個數

function checknumberlength(inputobj, beforelength, afterlength) [.]?//d$");

return regex.test(inputobj.value);

}else $");

return regex.test(inputobj.value);

}}//驗證最大長度指定的正負小數,inputobj為input物件,beforelength為小數點前面的位數個數,afterlength為小數點後面的位數個數

function checkallnumberlength(inputobj, beforelength, afterlength) [.]?//d$");

return regex.test(inputobj.value);

}else $");

return regex.test(inputobj.value);

}}//驗證最大長度指定的正負小數value

function checkallnumberlengthbyvalue(inputvalue, beforelength, afterlength) [.]?//d$");

return regex.test(inputvalue);

}else $");

return regex.test(inputvalue);

}}//測試輸入框的值是否帶小數

function checknumber(inputobj)

//測試輸入框的值是否小數

function checkallnumber(inputobj)

//測試身份證驗證

function checkidnumber(inputobj) $)|(^/d([0-9]|x)$)/;

return regex.test(inputobj.value);

}//測試身份證驗證

function checkemail(inputobj)

function keypress(inputobj)

else if (key == 46)

}function keypressallnumber(inputobj)

else if (key == 46)

else if (key == 45)

}//輸入整數

function keypressnum(objtr)

}function checkinputvalueisemptyoroverlength(inputobj, inputlength, inputfield)

if (!checklength(inputobj, inputlength))

return true;

}//將inputobj的文字全形轉半形

function dbc2sbc(inputobj)

else if (code == 12288)//空格

else

}inputobj.value = result;

}//判斷輸入的中英文

function checkbytelength(inputobj)

else

}return bytelen;

}else

}

JS函式驗證總結

去除左側空格 function ltrim str 去右空格 function rtrim str 去掉字串兩端的空格 function trim str 去除字串中間空格 function ctim str 是否為由數字組成的字串 function is digitals str 驗證是否為整數,...

js 驗證表單 js提交驗證類

附加 js驗證radio是否選擇 1.長度限制 2.只能是漢字 3.只能是英文 4.只能是數字 5.只能是英文本元和數字 6.驗證 油箱格式 7.遮蔽關鍵字 這裡遮蔽 和 8.兩次輸入密碼是否相同 夠了吧遮蔽右鍵 很酷 nc ntextmenu return false ndragstart ret...

常用js驗證

一 驗證類 1 數字驗證內 1.1 整數 d test str 1.2 大於0的整數 用於傳來的id的驗證 d test str 1.3 負整數的驗證 d test str 2 時間類 2.1 短時間,形如 13 04 06 function istime str d 2 d if a null i...