導航:首頁 > 凈水問答 > js正則過濾危險字元

js正則過濾危險字元

發布時間:2022-06-06 20:25:51

1. 如何用js或則jquery過濾特殊字元

1、jQuery使用正則匹配替換特殊字元

functionRegeMatch(){
varpattern=newRegExp("[~'!@#$%^&*()-+_=:]");
if($("#name").val()!=""&&$("#name").val()!=null){
if(pattern.test($("#name").val())){
alert("非法字元!");
$("#name").attr("value","");
$("#name").focus();
returnfalse;
}
}
}

2、jQuery限制輸入ASCII值

//數字0-9的ascii為48-57
//大寫A-Z的ascii為65-90
//小寫a-z的ascii為97-122

//----------------------------------------------------------------------
//<summary>
//限制只能輸入數字和字母
//</summary>
//----------------------------------------------------------------------
$.fn.onlyNumAlpha=function(){
$(this).keypress(function(event){
vareventObj=event||e;
varkeyCode=eventObj.keyCode||eventObj.which;
if((keyCode>=48&&keyCode<=57)||(keyCode>=65&&keyCode<=90)||(keyCode>=97&&keyCode<=122))
returntrue;
else
returnfalse;
}).focus(function(){
this.style.imeMode='disabled';
}).bind("paste",function(){
varclipboard=window.clipboardData.getData("Text");
if(/^(d|[a-zA-Z])+$/.test(clipboard))
returntrue;
else
returnfalse;
});
};


//-----調用方法$("#文本框id").onlyNumAlpha();


3、js正則匹配過濾

functionstripscript(s)
{
varpattern=newRegExp("[`~!@#$^&*()=|{}':;',\[\].<>/?~!@#¥……&*()——|{}【】『;:」「'。,、?]")
varrs="";
for(vari=0;i<s.length;i++){
rs=rs+s.substr(i,1).replace(pattern,'');
}
returnrs;
}

2. 怎麼用Js正則表達式去除特殊字元

正則表達式只能去測試字元串適合符合,返回true,false。並不能改變你的字元串(也就是說去除功能)

3. 用JS怎麼過濾 textarea 中的危險字元,如超鏈接<a></a>等

你可以寫個正則表達式去匹配下TEXTAREA裡面的那些標簽 將標簽去掉

4. Js字元串的正則匹配 如何過濾掉指定特徵的字元串

String.replace(正則表達式,"")
replace是string類型內置的替換方法,第一個參數可以是正則表達式,第二個版參數是想權要替換成的文本,正則中可以使用/g來表示替換所有匹配的文本,不使用則代表只替換匹配到的第一個字元對象,將第二個參數設為空字元串便可達到過濾的效果。
具體正則需要你自己去了解關於正則的知識了,祝你好運。

5. 在javascript中用正則表達式過濾指定的字元(一定要能指定!)

樓上的不加轉義字元\ 你們搞什麼啊
正確的應該是這樣的

加入你得到的內字元竄容為 name
<html>
<head>
<script>
function test1(){
var name=document.getElementById('user').value;
name=name.replace(/(\!+)|(\<+)|(\>+)|(\'+)/g,"");
alert(name);
}
</script>
</head>

<body>
<input type="text" id="user" />
<input type="button" value="te" onclick="test1()">
</body>
</html>

6. js 正則過濾特殊字元

您好

js檢查是否含有非法字元,js 正則過濾特殊字元

//正則
functiontrimTxt(txt){
returntxt.replace(/(^s*)|(s*$)/g,"");
}

/**
*檢查是否含有非法字元
*@paramtemp_str
*@returns{Boolean}
*/
functionis_forbid(temp_str){
temp_str=trimTxt(temp_str);
temp_str=temp_str.replace('*',"@");
temp_str=temp_str.replace('--',"@");
temp_str=temp_str.replace('/',"@");
temp_str=temp_str.replace('+',"@");
temp_str=temp_str.replace(''',"@");
temp_str=temp_str.replace('\',"@");
temp_str=temp_str.replace('$',"@");
temp_str=temp_str.replace('^',"@");
temp_str=temp_str.replace('.',"@");
temp_str=temp_str.replace(';',"@");
temp_str=temp_str.replace('<',"@");
temp_str=temp_str.replace('>',"@");
temp_str=temp_str.replace('"',"@");
temp_str=temp_str.replace('=',"@");
temp_str=temp_str.replace('{',"@");
temp_str=temp_str.replace('}',"@");
varforbid_str=newString('@,%,~,&');
varforbid_array=newArray();
forbid_array=forbid_str.split(',');
for(i=0;i<forbid_array.length;i++){
if(temp_str.search(newRegExp(forbid_array[i]))!=-1)
returnfalse;
}
returntrue;
}

---------------------

作者:dongsir 董先生

來源:董先生的博客

原文鏈接:js檢查是否含有非法字元

版權聲明:本作品採用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。轉載時請標註:http://dongsir.cn/p/195

7. 用JS如何寫正則表達式 用了屏蔽用戶輸入的非法文字

var valid=/[!@#$%^&*()]/; //你認為哪個是非常字元就加進去
var input;
....

if(!valid.test(input)){
//錯誤信息
}

8. js用什麼函數過濾非法字元防止跨站腳本攻擊

test
如:抄<input type="text" id="txtceshi" /><input type="button" onclick="yanzheng()" value="ceshi" />
<script type="text/javascript">
function yanzheng() {
var ce = txtceshi.value;//獲取文本框的值
var ze = /[^0-9]+/; //只能是數字,這里可以在網上找到一些正則替換成你想要的表達式
if (ze.test(ce)) {
alert("數據不合法!");
}
}
</script>

9. js中用正則表達式 過濾特殊字元 校驗所有輸入域是否含有特殊符號

樓上2位已經說的很明白了,只允許輸入規定的字元,如果輸入含有其他字元就直接提示,不允許輸入特殊字元,或者直接給它替換掉。

閱讀全文

與js正則過濾危險字元相關的資料

熱點內容
isapi過濾源代碼 瀏覽:603
企業污水監控內容 瀏覽:450
濾芯廠屬於什麼檔次 瀏覽:413
重慶商用純水設備多少錢 瀏覽:439
污水管網id是表示什麼 瀏覽:875
沁園凈水器洗滌口接哪個管 瀏覽:146
名圖空氣凈化器怎麼樣 瀏覽:722
空調濾芯有雜質是什麼原因 瀏覽:14
火神山醫院廢水處理 瀏覽:363
煙霧凈化器報警怎麼回事 瀏覽:643
使用中污水檢查井擴建 瀏覽:803
mb20水處理樹脂 瀏覽:22
電池加醫療蒸餾水行嗎 瀏覽:281
污水進水水質超標會導致什麼 瀏覽:946
超濾膜運行案例 瀏覽:20
污水處理廠對企業收費多少 瀏覽:897
反滲透膜被凍後有什麼影響 瀏覽:821
濟南污水處理稅收 瀏覽:233
窗戶下面是污水沉澱池 瀏覽:149
江蘇哪裡有派克濾芯報價 瀏覽:337