//------------------------------------------------------------------------------*/ // copyright notice */ // ~~~~~~~~~~~~~~~~ */ // copyright (c) 2003 by yongchuang electronic commerce co.,ltd. */ // */ // all rights reserved. this material is confidential and proprietary to */ // yongchuang electronic commerce co.,ltd. and no part of this material should */ // be reproduced,published in any form by any means,electronic or mechanical */ // including photocopy or any information storage or retrieval system nor */ // should the material be disclosed to third parties without the express */ // written authorization of yongchuang electronic commerce co.,ltd. */ // */ //------------------------------------------------------------------------------*/ //================================================================ // // file name : function.js // // file type : javascript source file // // author : andy wang // e-mail : king_wda@163.net // // purpose : common javascript function // // date : 05/20/2003 // // modification: 05/20/2003 // //================================================================ var numbers="0123456789"; var upperletters="abcdefghijklmnopqrstuvwxyz"; var lowerletters="abcdefghijklmnopqrstuvwxyz"; var specialchar="`~!@#$%^&*()_-+={}[]|\:;<>,.?/'"; var emailchar= numbers + upperletters + lowerletters + "@-_."; var englishchar= numbers + upperletters + lowerletters + "`~!@#$%^&()_-+={}[];,.'"; var letters=upperletters + lowerletters ; var alphanumeric=numbers + letters ; function isnumeric(thestring){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 validate whether the string is numeric // parameters : // name mode description // thenumber input the validated string // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- var num=thestring; num=num*1 + ""; if(num=="nan") return false; else return true; } function checkdate(formkey,elementname,separation){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 07/18/2003 the form element must no be blank // parameters : // formkey input the name or index of the form // elementname input the name or element // separation input the separation of the date string // // return value : true or false // return type : boolean // functions called : settextfocus // //-------------------------------------------------------------------------------- var thedate=document.forms[formkey].elements[elementname].value; var theyear,themonth,theday var arydate,intubound var result; arydate=thedate.split(separation) intubound=arydate.length; if(intubound!=3){ result=false; }else{ theyear=arydate[0]*1; themonth=arydate[1]*1; theday=arydate[2]*1; if(isnumeric(theyear) && isnumeric(themonth) && isnumeric(theday) ){ // 各段必须是数字 if(theyear<1900 || theyear>2500){ //- 年 result=false; }else{ if(themonth<1 || themonth>12){ //- 月 result=false; }else{ if(theday<1 || theday>31){ //- 日 result=false; }else{ result=true; } } } }else{ result=false; } } if(result==false){ alert("请输入格式正确的日期,如【2004" + separation + "5" + separation + "5】!"); settextfocus(formkey,elementname); } return result; } function ispositive(thestring){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 validate whether the string is positive number // parameters : // name mode description // thenumber input the validated string // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- if (isnumeric(thestring)) { if (thestring>=0){ return true; }else{ return false; } }else{ return false; } } function ispositiveinteger(thestring){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 validate whether the string is positive integer // parameters : // name mode description // thenumber input the validated string // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- //is numeric? if (isnumeric(thestring)) { var num=thestring*1 // >0 ? if (num>=0){ num=num+""; //include pointer "." ? if (num.indexof(".")==-1){ return true; }else{ return false; } }else{ return false; } }else{ return false; } } function isdate(thestring){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 validate whether the string is date // parameters : // name mode description // thenumber input the validated string // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- var thedate; thedate=date.parse(thestring)+""; if (thedate=="nan" ) return false; else return true; } function checkpassword(password,haveupper,havelower,havespecial,minlen,maxlen){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 validate format of the password // parameters : // name mode description // password input the validated password // haveupper input indicate password must have uppercase letter // havelower input indicate password must have lowercase letter // havespecial input indicate password must have special letter // minlen input indicate minimum length of password // maxlen input indicate maximal length of password // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- var i; var chr; var blnfound; var len; len=password.length; //length must be between minlen and maxlen if (len maxlen){ return false; } //must have uppercase letters if (haveupper==true){ blnfound=false; for(i=0;imaxlen){ alert(promptstring); settextfocus(formkey,elementname); return false; } } return true; } function checksilimartext(formkey,prefix,checkboxname,mixlen,maxlen,promptstring){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 07/18/2003 the form element must no be blank // parameters : // formkey input the name or index of the form // prefix input the name prefix of the text // checkboxname input the name or check box control array // minlen input the min length // maxlen input the max length, -1 : infinite // promptstring input the prompted string // // return value : if check successfully return true ,otherwise return false // return type : boolean // functions called : mustnotblank // //-------------------------------------------------------------------------------- var theform=document.forms[formkey]; var elementname; var i,len; var id; len=theform.elements[checkboxname].length; for(i=0;imaxlen){ alert(promptstring); settextfocus(formkey,elementname); return false; } } return true; } function checknumber(formkey,elementname,promptstring,onlyinteger,onlypositive){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 05/21/2003 check value of the text is number // // parameters : // name mode description // formkey input the name or index of the form // elementname input the name or element // promptstring input the prompted string // onlyinteger input only integer // onlypositive input only positive // // return value : true/false // return type : boolean //-------------------------------------------------------------------------------- var i,len; var strvalue=document.forms[formkey].elements[elementname].value; //- delete all blank strvalue=stringreplace(strvalue," ",""); document.forms[formkey].elements[elementname].value=strvalue; len=strvalue.length; var bechartok=true; var strnumbers=numbers; if(onlyinteger==false){ strnumbers=strnumbers + "."; } if(onlypositive==false){ strnumbers=strnumbers + "-"; } //check each character for(i=0;i