資源描述:
《html.js中的表單驗(yàn)證》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、//常用驗(yàn)證類functionNfValidate(){}//Email格式驗(yàn)證NfValidate.isEmail=function(value){varpattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+.([[a-zA-Z0-9_-])+/;returnpattern.test(value);}//整數(shù)格式驗(yàn)證NfValidate.isInteger=function(value){varpattern=/^[-+]?d*$/;returnpattern.test(value)}//雙精度格式驗(yàn)證NfValidate.i
2、sDouble=function(value){varpattern=/^[-+]?d+.(d+)?$/;returnpattern.test(value);}//一位小數(shù)格式驗(yàn)證NfValidate.isOneDecimal=function(value){varpattern=/^-?d+.(d{1,1})?$/;returnpattern.test(value);}//二位小數(shù)格式驗(yàn)證NfValidate.isTwoDecimal=function(value){varpattern=/^-?d+.(d{1,2})?$/;returnpat
3、tern.test(value);}//三位小數(shù)格式驗(yàn)證NfValidate.isThreeDecimal=function(value){varpattern=/^-?d+.(d{1,3})?$/;returnpattern.test(value);}//驗(yàn)證小數(shù)位數(shù)NfValidate.checkNumDecimal=function(value,num){if(value!=""){if(value.indexOf(".")>0){vartemp=value.length-(value.indexOf(".")+1);if(temp==num){ret
4、urntrue;}}}returnfalse;}//驗(yàn)證英文字母NfValidate.isLetter=function(value){varpattern=/^[a-zA-Z]+$/;returnpattern.test(value);}//驗(yàn)證中文字符NfValidate.isChinese=function(value){varpattern=/^[u0291-uFFE5]+$/;returnpattern.test(value);}//驗(yàn)證身份證號(hào)碼NfValidate.isCardID=function(value){varpattern=/(^([
5、d]{15}
6、[d]{18}
7、[d]{17}[xX]{1})$)/;returnpattern.test(value);}//驗(yàn)證郵編格式NfValidate.isZipCode=function(value){varpattern=/^d{6}$/;returnpattern.test(value);}//驗(yàn)證電話號(hào)碼格式NfPhone.isPhone=function(value){varpattern=/^(([0+]d{2,3}-)?(0d{2,3})-)?(d{7,8})(-(d{3,}))?$/;returnpattern.test(
8、value);}//驗(yàn)證手機(jī)號(hào)碼格式NfValidate.isMobile=function(value){varpattern1=/^13d{5,9}$/;varpattern2=/^153d{4,8}$/;varpattern3=/^159d{4,8}$/;returnpattern1.test(value)
9、
10、pattern2.test(value)
11、
12、pattern3.test(value);}