?? ubb.jsp
字號:
<%@ page import="java.util.regex.*" %>
<%!
public class checkData{
/** 傳入的需要匹配的參數 */
String s = null;
/** Pattern 類型的 p */
Pattern p;
/** Matcher 類型的 m */
Matcher m;
//////////////////
String u_s = new String("haha");
String u_s1 = new String("haha");
Pattern u_p;
Matcher u_m;
CharSequence u_s2;
boolean result;
///////////////////
//構造函數
checkData(String ins){
this.s = ins;
}
public void setS(String ins){
this.s = ins;
}
public String getS(){
return this.s;
}
/**
---->檢測Email是否正確
*/
//返回值:布爾值(boolean)
public boolean checkMail(){
if(this.s.equals("")) return false;
try{
p = Pattern.compile("^[a-z_\\-0-9]+\\@[a-z_\\.\\-0-9]+$",Pattern.CASE_INSENSITIVE);
m = p.matcher(this.s);
return m.matches();
}
catch(Exception e){return false;}
}
/**
---->檢測處理用戶輸入的用戶名是否合法
*/
// 返回值:布爾值(boolean)
public boolean checkNick(){
if(this.s.equals("")) return false;
try{
p = Pattern.compile("^[^\\|\\@!|#|\\$|%|\\^|&|*|\\(|\\)|,|;|:|\"|'|\\.|\\?|<|>|\\/|\\+|=|\\]|\\[|\\{|\\}]+?$",Pattern.CASE_INSENSITIVE);
m = p.matcher(this.s);
return m.matches();
}
catch(Exception e){return false;}
}
/**
---->檢測輸入的網址是否合法
*/
// 返回值:布爾值(boolean)
public boolean checkUrl(){
if(this.s.equals("")) return false;
try{
p = Pattern.compile("^(http:\\/\\/)|(www\\.)[{1}a-z_\\-0-9\\.\\/]+$",Pattern.CASE_INSENSITIVE);
m = p.matcher(this.s);
return m.matches();
}
catch(Exception e){return false;}
}
/**
----->處理一些特殊字符
*/
//返回值:字符串(String)
public String killHtml(boolean t){
if(t) s = s.trim();
s = s.replaceAll("<","<");
s = s.replaceAll(">",">");
s = s.replaceAll(" "," ");
s = s.replaceAll("#_#","#__#");
s = s.replaceAll("\n","<br>");
s = s.replaceAll("<!--newLine-->","");
return s;
}
public String formatHtml(boolean t){
if(t) s = s.trim();
s = s.replaceAll("<","<");
s = s.replaceAll(">",">");
s = s.replaceAll(" "," ");
s = s.replaceAll("#_#","#__#");
s = s.replaceAll("\n","<br>");
s = s.replaceAll("<!--newLine-->","");
return s;
}
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -