/* 验证邮箱 */
public static boolean IsEmail(String Input) {
String reg = "^([a-z0-9A-Z]+[-|_|\\\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\\\.)+[a-zA-Z]{2,}$";
return Pattern.matches(reg, Input);
}
/* 验证手机号 */
public static boolean IsPhone(String Input) {
String reg = "^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\\\d{8})|(0\\\\d{2}-\\\\d{8})|(0\\\\d{3}-\\\\d{7})$";
return Pattern.matches(reg, Input);
}
/* 验证座机号 */
public static boolean IsTel(String Input) {
String reg = "(\\\\(\\\\d{3,4}\\\\)|\\\\d{3,4}-|\\\\s)?\\\\d{8}";
return Pattern.matches(reg, Input);
}
/* 验证传真 */
public static boolean IsFax(String Input) {
String reg = "^[+]{0,1}(\\\\d){1,3}[ ]?([-]?((\\\\d)|[ ]){1,12})+$";
return Pattern.matches(reg, Input);
}
/* 验证邮编号码 */
public static boolean IsCode(String Input) {
String reg = "^\\\\d{6}$";
return Pattern.matches(reg, Input);
}
/* 验证是否正确的网络地址 */
public static boolean IsInternetUrl(String Input) {
String reg = "[a-zA-z]+://[^\\\\s]*";
return Pattern.matches(reg, Input);
}
/* 验证正确的姓名 */
public static boolean IsName(String Input) {
String reg = "[a-zA-Z]{1,20}|[\\u4e00-\\u9fa5]{1,10}";
return Pattern.matches(reg, Input);
}
/* 验证正确的英文名 */
public static boolean IsEName(String Input) {
String reg = "[a-zA-Z]{1,20}";
return Pattern.matches(reg, Input);
}
/* 验证正确的日期格式 */
public static boolean IsData(String Input) {
String reg = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|"
+ "(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|"
+ "(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|"
+ "(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|" + "((16|[2468][048]|[3579][26])00))-0?2-29-))$";
return Pattern.matches(reg, Input);
}
/* 验证是否是SQL语句 */
public static boolean IsSQL(String Input) {
String reg = "\\?|Truncate%20|Truncate\\s+|ALTER%20|ALTER\\s+|select%20|select\\s+|insert%20|insert\\s+|delete%20|delete\\s+|count\\(|drop%20|drop\\s+|update%20|update\\s+";
return Pattern.matches(reg, Input);
}
/* 验证是否为Ip */
public static boolean IsIp(String Input) {
String reg = "^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$";
return Pattern.matches(reg, Input);
}
/* 验证是否为URL */
public static boolean IsUrl(String Input) {
String reg = "^(http|ftp|file)://.*";
return Pattern.matches(reg, Input);
}
/* 验证身份证号 */
public static boolean CheckIDCard(String Id) {
boolean check;
if(Id.length() == 18) {
check = true;
}else {
check = false;
}
return check;
}
后端常用字段验证
最新推荐文章于 2023-08-17 11:26:21 发布