當前位置:首頁 » 凈水方式 » 過濾特殊字元

過濾特殊字元

發布時間: 2020-12-20 05:55:05

『壹』 java正則表達式過濾特殊字元

Stringregexp="[^'"%]*";
Stringstring="abc%";
System.out.println(string.matches(regexp));

『貳』 asp中如何過濾掉特殊字元

|user=replace(trim(request.form("uName")),"'","''")
password=replace(trim(request.form("Password")),"'","''")
if instr(user,"%") or instr(user,"#") or instr(user,"?") or instr(user,"|") or instr(user,"'") then
response.write "<script language=javascript>alert('您的姓名含有非法字元!');this.location.href='login.asp';</script>"
response.end
end if

if instr(password,"%") or instr(password,"#") or instr(password,"?") or instr(password,"|") then
response.write "<script language=javascript>alert('您的密碼含有非法字元!');this.location.href='login.asp';</script>"
response.end
end if 我自己做的,希望對你有幫助

『叄』 如何過濾特殊字元和亂碼的字元

這是編碼引起的,來把資料庫表的那個自欄位編碼改成utf-8格式 alter table user(表名) CHANGE old(老欄位) new(新欄位) varchar(100) charset utf8 後面的語句的編碼就是utf8,不要改成utf-8,MySQL不識別,不用改欄位名稱就直接都寫原來的欄位名。

『肆』 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

『伍』 jsp\java 如何編寫過濾器過濾特殊字元

package com.jing.common;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class IllegalCharacterFilter implements Filter {
private String[] characterParams = null;
private boolean OK=true;

public void init(FilterConfig config) throws ServletException {

// if(config.getInitParameter("characterParams").length()<1)
// OK=false;
// else
// this.characterParams = config.getInitParameter("characterParams").split(",");
System.out.println("初始化");
}

@SuppressWarnings("unchecked")
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest servletrequest = (HttpServletRequest) request;
HttpServletResponse servletresponse = (HttpServletResponse) response;
String param = "";
String paramValue = "";

//設置請求編碼格式
servletresponse.setContentType("text/html");
servletresponse.setCharacterEncoding("UTF-8");
servletrequest.setCharacterEncoding("UTF-8");
java.util.Enumeration params = request.getParameterNames();
//循環讀取參數
while (params.hasMoreElements()){
param = (String) params.nextElement(); //獲取請求中的參數
String[] values = servletrequest.getParameterValues(param);//獲得每個參數對應的值

for (int i = 0; i < values.length; i++) {

paramValue = values[i];

//轉換目標字元變成對象字元,可以多個。後期擴展特殊字元庫用於管理
paramValue = paramValue.replaceAll("'","");
paramValue = paramValue.replaceAll("@","");
paramValue = paramValue.replaceAll("胡錦濤","***");

//這里還可以增加,如領導人 自動轉義成****,可以從資料庫中讀取非法關鍵字。
values[i] = paramValue;

}

//把轉義後的參數重新放回request中
request.setAttribute(param, paramValue);
}
//繼續向下 執行請求,如果有其他過濾器則執行過濾器
arg2.doFilter(request, response);
}

public void destroy() {
// TODO Auto-generated method stub
}
}

『陸』 如何用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;
}

『柒』 PHP 如何過濾特殊字元 如 ◆ )- : 、 、!! / 等

^

PHP 中的 preg_replace() 函數可以實現

實例:只匹配中文


<?php
$str="php)!內!編程";
echopreg_replace("/[^容x{4e00}-x{9fa5}]/iu",'',$str);
?>

『捌』 jQuery 過濾html標簽屬性的特殊字元

您好,如果在表單中需要提交一字元串,其中包含,< > " &字元時,當我們把這字元串顯示到jsp頁面時,會和html標簽產生沖突,導致web頁面的某些部分消失或者格式不正確。為了解決以上問題,需要在顯示之前,對字元串進行代碼過濾。
把字元串中的 < 替換為 &It;
> 替換為 >
" 替換為 "
& 替換為 &
這里給出一個靜態的過濾代碼,供大家參考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}else if(ch == '"'){
buf.append(""");
}else if(ch == '&'){
buf.append("&");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
}
此時,只需在jsp中對字元串調用此方法(StringUtils.escapeHTMLTags(str))即可。

『玖』 如何過濾MAP中的特殊字元

|//用來防頁面上輸入的帶有破壞性內容
Map<String, String> map = new HashMap<String, String>();
map.put("1", "value1");
map.put("2", "value2");
map.put("3", "value3");
for(Iterator iterator = dataMap.entrySet().iterator(); iterator.hasNext();){
Map.Entry m = (Entry) iterator.next();
String mapValue = (String) m.getValue();
if("".equals(mapValue)||mapValue!=null){
String result = "";

//將取出的值進行相關操作版然後再塞到Map里權
......
m.setValue(result);
}
}

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239