JS代碼判斷集錦大全第1/5頁(yè)
更新時(shí)間:2007年12月06日 21:15:02 投稿:mdxy-dxy
本文通過(guò)實(shí)例代碼給大家介紹了js代碼判斷的方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
具體代碼如下所示:
<script language="JavaScript"> function checkid(iden,year,month,day){ if (iden.value.length==15) { if ((iden.value.lastIndexOf(month.value+day.value))==8) { return true; } return false; } if (iden.value.length==18) { if ((iden.value.indexOf(year.value+month.value+day.value))==6) { return true; } return false; } return false; } function isCharsInBag (s, bag) { var i; for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (bag.indexOf(c) == -1) return false; } return true; } function isEmpty(s) { return ((s == null) || (s.length == 0)) } function isWhitespace (s) { var whitespace = " \t\n\r"; var i; for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (whitespace.indexOf(c) >= 0) { return true; } } return false; } function isEmail (s,t) { if (isEmpty(s)) { window.alert("輸入的E-mail地址不能為空,請(qǐng)輸入!"); mobj = eval(t); mobj.focus(); mobj.select(); return false } if (isWhitespace(s)) { window.alert("輸入的E-mail地址中不能包含空格符,請(qǐng)重新輸入!"); mobj = eval(t) mobj.focus() mobj.select() return false; } var i = 1; var len = s.length; if (len > 50) { window.alert("email地址長(zhǎng)度不能超過(guò)50位!"); mobj = eval(t) mobj.focus() mobj.select() return false; } pos1 = s.indexOf("@"); pos2 = s.indexOf("."); pos3 = s.lastIndexOf("@"); pos4 = s.lastIndexOf("."); if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len)) { window.alert("請(qǐng)輸入有效的E-mail地址!"); mobj = eval(t) mobj.focus() mobj.select() return false; } else { if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) || ( pos1 != pos3 ) || ( pos4 < pos3 ) ) { window.alert("請(qǐng)輸入有效的E-mail地址!"); mobj = eval(t) mobj.focus() mobj.select() return false; } } if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@")) { window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "請(qǐng)重新輸入" ); mobj = eval(t) mobj.focus() return false; } return true; } function isnumber(str){ var digits="1234567890"; var i=0; var strlen=str.length; while((i<strlen)){ var char=str.charAt(i); if(digits.indexOf(char)==-1)return false;i++; } return true; } function isnumbercode(str){ var digits="1234567890-/"; var i=0; var strlen=str.length; while((i<strlen)){ var char=str.charAt(i); if(digits.indexOf(char)==-1)return false;i++; } return true; } </script> <script language=javascript> function checkForm(theform){ if (document.frm.companyname.value.length==0){ alert("單位名稱不能為空。"); mobj = eval("document.frm.companyname"); mobj.focus() mobj.select() return false; } if (document.frm.address.value.length==0){ alert("單位地址不能為空"); mobj = eval("document.frm.address"); mobj.focus() mobj.select() return false; } if (document.frm.invest.value.length==0){ alert("投資額不能為空"); mobj = eval("document.frm.invest"); mobj.focus() mobj.select() return false; } if (document.frm.codeornumber.value.length==0){ alert("法人代碼證書(shū)號(hào)或營(yíng)業(yè)執(zhí)照編號(hào)不能為空"); mobj = eval("document.frm.codeornumber"); mobj.focus() mobj.select() return false; } if (document.frm.linkman.value.length==0){ alert("聯(lián)系人不能為空"); mobj = eval("document.frm.linkman"); mobj.focus() mobj.select() return false; } if (document.frm.linkmanjob.value.length==0){ alert("聯(lián)系人職位不能為空"); mobj = eval("document.frm.linkmanjob"); mobj.focus() mobj.select() return false; } if (document.frm.phone.value.length==0){ alert("電話不能為空"); mobj = eval("document.frm.phone"); mobj.focus() mobj.select() return false; } if (document.frm.email.value=='') { window.alert ("請(qǐng)輸入您的E-mail地址 !") mobj = eval("document.frm.email"); mobj.focus() mobj.select() return false } if ( !isEmail(document.frm.email.value,document.frm.email) ) return false if (document.frm.introduction.value.length==0){ alert("公司簡(jiǎn)介不能為空"); mobj = eval("document.frm.introduction"); mobj.focus() mobj.select() return false; } if (document.frm.positionname.value.length==0){ alert("職位名稱不能為空"); mobj = eval("document.frm.positionname"); mobj.focus() mobj.select() return false; } if (document.frm.jobaddress.value.length==0){ alert("工作地點(diǎn)不能為空"); mobj = eval("document.frm.jobaddress"); mobj.focus() mobj.select() return false; } if (document.frm.jobfunction.value.length==0){ alert("工作職責(zé)不能為空"); mobj = eval("document.frm.jobfunction"); mobj.focus() mobj.select() return false; } if (document.frm.positionrequre.value.length==0){ alert("職位要求不能為空"); mobj = eval("document.frm.positionrequre"); mobj.focus() mobj.select() return false; } if (document.frm.salary.value.length==0){ alert("待遇不能為空"); mobj = eval("document.frm.salary"); mobj.focus() mobj.select() return false; } } </script> JS代碼判斷集錦(之二)
相關(guān)文章
原生js實(shí)現(xiàn)fadein 和 fadeout淡入淡出效果
這篇文章主要介紹了通過(guò)原生js實(shí)現(xiàn)fadein 和 fadeout淡入淡出效果,需要的朋友可以參考下2014-06-06javascript設(shè)計(jì)模式--策略模式之輸入驗(yàn)證
策略模式中的策略就是一種算法或者業(yè)務(wù)規(guī)則,將這些策略作為函數(shù)進(jìn)行封裝,并向外提供統(tǒng)一的調(diào)用執(zhí)行,本文給大家介紹javascript設(shè)計(jì)模式--策略模式之輸入驗(yàn)證,需要的朋友參考下2015-11-11實(shí)例詳解BootStrap的動(dòng)態(tài)模態(tài)框及靜態(tài)模態(tài)框
要用bootStrap這個(gè)框架就必須要重載它的class類(lèi),也就是說(shuō)class要一樣。接下來(lái)通過(guò)實(shí)例代碼給大家介紹BootStrap的動(dòng)態(tài)模態(tài)框及靜態(tài)模態(tài)框,需要的朋友可以參考下2018-08-08JS實(shí)現(xiàn)仿新浪微博發(fā)布內(nèi)容為空時(shí)提示功能代碼
這篇文章主要介紹了JS實(shí)現(xiàn)仿新浪微博發(fā)布內(nèi)容為空時(shí)提示功能,2015-08-08JavaScript中利用Array和Object實(shí)現(xiàn)Map的方法
這篇文章主要介紹了JavaScript中利用Array和Object實(shí)現(xiàn)Map的方法,實(shí)例分析了javascript實(shí)現(xiàn)map的添加、獲取、移除、清空、遍歷等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07微信小程序自定義純凈模態(tài)框(彈出框)的實(shí)例代碼
這篇文章主要介紹了微信小程序自定義純凈模態(tài)框(彈出框)的實(shí)例代碼,代碼簡(jiǎn)答易懂,非常不錯(cuò),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03