validate.js

来自「ASP.NET的一些开发实例,有论坛管理系统等」· JavaScript 代码 · 共 39 行

JS
39
字号
//----------------------------------------------------------------------------
/* function: to validate the Client input data type and length
   param1(required): sToVerify -- String to be verified
   param2(required): iBinLenReqest -- Number of Binary Length of the String to be verified
                     send 0 if no limit
   return: --String, passed verified of length and replace of "'" to "’"
           --False, not passed
*/
function ClientInputVerify(sToVerify, iBinLenRequest){
	if(iBinLenRequest.NaN){return false;}
	var arrElm;
	sToVerify=sToVerify.replace(/[']/g,"’");
	sToVerify=sToVerify.replace(/["]/g,"”");
	sToVerify=sToVerify.replace(/[%]/g,"%");
	sToVerify=sToVerify.replace(/[&]/g,"·");
	sToVerify=sToVerify.replace(/[*]/g,"*");
	sToVerify=sToVerify.replace(/[(]/g,"(");
	sToVerify=sToVerify.replace(/[)]/g,")");
	sToVerify=sToVerify.replace(/\[/g,"[");
	sToVerify=sToVerify.replace(/\]/g,"]");
	sToVerify=sToVerify.replace(/[<]/g,"〈");
	sToVerify=sToVerify.replace(/[>]/g,"〉");
	sToVerify=sToVerify.replace(/[?]/g,"?");
	arrElm = sToVerify.split("");
	var iBinLen = new Number(0);
	for(i=0;i<arrElm.length;i++){
		if(arrElm[i].charCodeAt()>255){
			iBinLen+=2;
		}
		else{iBinLen++}
	}
	if((iBinLen>iBinLenRequest)&&iBinLenRequest!=0){
		return false;
	}
	else{
		return sToVerify;
	}
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?