后端常用字段验证

/* 验证邮箱 */
	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;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值