现在我作了修改了,用另外一种方法实现了.以下是我的修改后的代码:
(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)script language="JavaScript"/***Title:check TestNumber Code*Time:2007-02-08*Author:colinmok*/function subForm(){ var mobile=document.frmSubmit.mobile.value;if(mobile==""){document.write("请输入号码!");document.write("a href='blackwhiteuseradd.jsp'返回/a");return false;}}function CheckTestNumber(){var mobile=document.frmSubmit.mobile.value;if(mobile==""){document.write("请输入号码!");document.write("a href='blackwhiteuseradd.jsp'返回/a");return false;}var mobile_trim=mobile.trim();var mobile_AllTrim=mobile_trim.AllTrim();var mobile_temp=mobile_AllTrim.replace(//g,"#");//用#号替换回车换行if(TestNumber(mobile_temp)){return false;}}/***判断输入的号码是否是测试号码*/function TestNumber(mobile){ //测试号码var TestNumber=new Array("13450276173","13049650535","13168866450","02039514090","02031482087");for(var i=0;iTestNumber.length;i++){var a=mobile.indexOf(TestNumber[i]);//查找用户输入的号码中是否存在测试号码if(a=0){var pos=a/11;document.write("第"+parseInt(pos+1)+"个号码"+TestNumber[i]+"是测试手机号");document.write("a href='blackwhiteuseradd.jsp'返回/a");return true;}}}//构造去掉空格函数String.prototype.trim=function(){/*** 用正则表达式将前后空格* 用空字符串替代*/return this.replace(/(^s*)|(s*$)/g, "");}// 除去空格函数String.prototype.AllTrim= function(){ var regEx = /s*/g; return this.replace(regEx,''); }//结束/script(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)