正则验收:对邮箱、手机号码、身份证、电话、整数、正数、字符串是否为空等一些验证


package com.jn.commons.utils;

import java.awt.Image;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.imageio.ImageIO;

/**
 * ClassName:validateUtils <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2016年5月31日 上午11:48:21 <br/>
 * 
 * @author liuweiying
 * @version
 * @since JDK 1.6
 * @see
 */
public class ValidateUtils {
	/**
	 * isPhone:(判断是否是手机号码). <br/>
	 *
	 * @author liuweiying
	 * @param phone
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isMobliePhone(String phone) {
		Pattern phonePattern = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,1,5-9]))\\d{8}$");
		Matcher matcher = phonePattern.matcher(phone);
		if (matcher.find()) {
			return true;
		}
		return false;
	}

	/**
	 * isEmail:(判断是否为正确的邮件格式). <br/>
	 *
	 * @author liuweiying
	 * @param str
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isEmail(String emali) {
		if (isEmpty(emali))
			return false;
		return emali.matches("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
	}

	/**
	 * isPhone:(是否是电话号码). <br/>
	 *
	 * @author liuweiying
	 * @param phone
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isPhone(String phone) {
		if (isEmpty(phone)) {
			return false;
		}
		return phone.matches("0\\d{2,3}-\\d{7,8}");

	}

	public static boolean isIdcard(String idcard) {
		if (isEmpty(idcard)) {
			return false;
		}
		return idcard.matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X|x)$");
		// return idcard.matches("^(\\d{18,18}|\\d{15,15}|\\d{17,17}(x|X))$");

	}

	/**
	 * isNumber:(判断是否为整数). <br/>
	 *
	 * @author liuweiying
	 * @param str
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isInteger(String num) {
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
		Matcher isNum = pattern.matcher(num);
		if (isNum.matches()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * isNumber:(是否是正数). <br/>
	 *
	 * @author liuweiying
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isNumber(String num) {
		Pattern pattern = Pattern.compile("^[0-9]*|[0-9]*.[\\d]*$");
		Matcher isNum = pattern.matcher(num);
		if (isNum.matches()) {
			return true;
		} else {
			return false;
		}

	}


	/**
	 * isEmpty:(判断字符串是否为空【包含null与""】 ). <br/>
	 *
	 * @author liuweiying
	 * @param str
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isEmpty(String str) {
		if (str == null || "".equals(str))
			return true;
		return false;
	}

	/**
	 * isEmptyIgnoreBlank:(判断字符串是否为空【包含null与"","    "】). <br/>
	 *
	 * @author liuweiying
	 * @param str
	 * @return
	 * @since JDK 1.6
	 */
	public static boolean isEmptyIgnoreBlank(String str) {
		if (str == null || "".equals(str) || "".equals(str.trim()))
			return true;
		return false;
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值