You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hunjianghu/WeChat/sqlfilter.java

25 lines
798 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package WeChat;
// 过滤掉奇奇怪怪的英文字符
public class sqlfilter {
private static String danger="`~!@#$^&*()=|{}';'\\[].<>/?~@#¥……&*——|{}";
public static boolean isNumber(String text) {
if(text == null) return false;
int length = text.length();
if(length>10) return false;
for(int i=0; i<length; i++){
char digit = text.charAt(i);
if(!(digit>='0'&&digit<='9')) return false;
}
return true;
}
public static String filter(String sqlQue) {
StringBuffer ft = new StringBuffer();
for (int i=0; i<sqlQue.length(); i++) {
char sign = sqlQue.charAt(i);
if (danger.indexOf(sign) == -1) ft.append(sign);
}
return ft.toString();
}
}