资源描述:
《输入限制(用js)(input restriction (using js))》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、输入限制(用js)(Inputrestriction(usingJS))Jscode1.//mailcheck2./thecheckreturnture,otherwiseitreturnsfalse3.,function,isEmail(emailStr)...{4.if(emailStr.length==0){...5.returnfasle;6.}else...{7.varemailPat=/^(1)@($/1);8.varspecialChars="(\);<>@,:".[]";9.varvalidChars=,"[^s"+specialChars+"]";10
2、.varquotedUser="("[^"]*")";11.varipDomainPat=/^(D...{1,3})[.](D...{1,3})[.](D...{1,3})[.]({1,3}/D...);Varatom=validChars++12;13.varword="("+atom+"
3、"+quotedUser+")";14.varuserPat=newRegExp("^"+word+"(."+word+")*$");15.vardomainPat=newRegExp("^"+atom+"(."+atom+")*$");16.varmatchArray=emailStr.ma
4、tch(emailPat);17.if(matchArray==null){...18.returnfalse;19.}20.varuser=matchArray[1];21.vardomain=matchArray[2];22.if(user.match(userPat)==null){...23.returnfalse;24.}25.varIPArray=domain.match(ipDomainPat);26.if(IPArray==null){27.for(VaRI=1;I<4;i++){...28.if(IPArray[i]>255){29.returnfalse;30.
5、}31.}32.returntrue;33.}34.vardomainArray=domain.match(domainPat);35.if(domainArray==null){...36.returnfalse;37.}38.,VaR,atomPat=new,RegExp(atom,G);39.vardomArr=domain.match(atomPat);40.varlen=domArr.length;If(41.(domArr[domArr.length-1].length<2)
6、
7、42.(domArr[domArr.length-1].length>3)){43.retu
8、rnfalse;44.}45.if(len<2){46.returnfalse;47.}48.returntrue;49.}50.}Fifty-oneFifty-two53.//IPaddresscheck54./thecorrectIPaddressbacktoture,otherwiseitreturnsfalse55.,function,isIp(strIp)...{56.var(ipDomainPat=/^(2[0-4]d
9、25[0-5]
10、[01]?DD?{3}(2[0-4]d
11、25[0-5]
12、[01]).)...?/DD?);57.varmatchArray=strIp.
13、match(ipDomainPat);58.if(matchArray...=null){59.returntrue;60.}61.}Sixty-twoSixty-three64.//telephonenumbercheck65./thecorrectphonenumber(includingareacodeand"-"suchas0571-1234567[8]010-1234567[8])returnsture,otherwiseitreturnsfalse66.,function,isTelphoneNum(telNum)...{67.,VaR,telphoneNumPat=/
14、^0d...{2}-d...{7,8}
15、0d...{3}-d...{7,8}$/..;68.varmatchArray=telNum.match(telphoneNumPat);69.if(matchArray...=null){70.returntrue;71.}72.}Seventy-threeSeventy-four75.//mobilephonenumbercheck76./thecorrectmobilephonenumber(138005715060138