📄 validate.java
字号:
package com.set.utils;
import java.util.regex.Pattern;
public class Validate {
public Validate() {
}
// 验证表单数据
public static String parsetype(String type, String content) {
String flag = "";
if (type.equals("mobile")) {
// ----2006-9-4---修改手机号码验证 可以验证153/159号码段
String mobilePattern = "[1]{1}(3|5){1}[0-9]{9}";
// if
// (!Pattern.compile("^((\\(\\d{3}\\))|(\\d{3}\\-))?13\\d{9}$").matcher(content).
if (!Pattern.compile(mobilePattern).matcher(content).matches()) {
flag = "lost";
}
} else if (type.equals("mail")) {
if (!Pattern.compile(
"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")
.matcher(content).matches()) {
flag = "lost";
}
} else if (type.equals("date")) {
if (!Pattern.compile(
"^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$")
.matcher(content).matches()) {
flag = "lost";
}
}
// else if (type.equals("string")) {
// if (!Pattern.compile(
// "[^\\x00-\\xff]").
// matcher(content).matches()) {
// flag = "lost";
// }
//
// }
else if (type.equals("int")) {
if (!Pattern.compile("^[-\\+]?\\d+$").matcher(content).matches()) {
flag = "lost";
}
} else if (type.equals("tel")) {
if (!Pattern
.compile(
"^((\\(\\d{3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}$")
.matcher(content).matches()) {
flag = "lost";
}
} else if (type.equals("double")) {
if (!Pattern.compile("^[-\\+]?\\d+(\\.\\d+)?$").matcher(content)
.matches()) {
flag = "lost";
}
} else if (type.equals("website")) {
if (!Pattern.compile(
"http://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?").matcher(
content).matches()) {
flag = "lost";
}
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -