導航:首頁 > 凈水問答 > js過濾指定字元

js過濾指定字元

發布時間:2023-08-13 08:32:17

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

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

B. js 如何過濾div里內的指定字元

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

C. 在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>

D. js字元過濾

先將表單的欄位值送入一個字元串答握變數清信慶中,如str。
然後str.indexOf("字坦腔眼")>0,屏蔽它。

E. 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

F. 如何用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;
}

G. 簡單的用js實現過濾多餘字元的正則表達式

利用正則表達法除去字元串中的重復字元
str
=
"Google"
str1
=
str.replace(/(.).*\1/g,"$1")
document.write(str
+
"
");
document.write(str1);
[Ctrl+A
全選
注:如需引入外部Js需刷新才能執行]

閱讀全文

與js過濾指定字元相關的資料

熱點內容
為什麼家用凈水機的水仍有水垢 瀏覽:572
空調提升泵不做提升可以嗎 瀏覽:118
砂濾棒過濾器工作原理 瀏覽:625
月子里用護膚品會不會回奶 瀏覽:464
碧麗直飲水機怎麼解鎖 瀏覽:314
槽下凈水器哪個好 瀏覽:396
地熱循環泵靜音家用能提升幾度 瀏覽:917
污水處理設備處理完的水叫什麼 瀏覽:748
生活污水池種什麼最好 瀏覽:35
常州水處理環保有限公司怎麼樣 瀏覽:633
asf旁濾過濾器在循環水廠的使用論文 瀏覽:365
2012軒逸經典空調濾芯怎麼換 瀏覽:260
長安污水處理原理是怎麼來的 瀏覽:196
千里寫過濾器 瀏覽:853
ro膜串聯 瀏覽:348
吉利博瑞ge拆空氣濾芯用什麼工具 瀏覽:482
污水提升裝置和潛污泵 瀏覽:675
磷肥生產廢水處理 瀏覽:496
microboy提升泵 瀏覽:43
飲水機熱水孔時好時壞怎麼回事 瀏覽:983