这是一款用来在客户端过滤一些非法字符,可以防止一些不必要提供,更显得用户友好提示哦
javascript教程 过滤非法字符验证程序
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript 过滤非法字符验证程序</title>
<script language="javascript">
function EncodeUrl(str){
var strUrl=str.replace(/r/g,"%0A");
strUrl=strUrl.replace(/n/g,"%0D");
strUrl=strUrl.replace(/"/g,"%22");
strUrl=strUrl.replace(/'/g,"%27");
return strUrl;
}
function check111net()
{
var www111cnNet= $('111cnNet').value;
EncodeUrl(www111cnNet);
}
function $(id)
{
return document.getElementById(id);
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="text" name="textfield" id="111cnNet">
</label>
<p>
<label>
<input type="submit" name="button" id="button" value="提交" onClick="javascript:return check111net();">
</label>
</p>
</form>
</body>
</html>