java验证是否是手机号 数字 邮箱 英文 字符


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegUtil {
	/**
	 * 验证手机号码是否正确
	 * @param mobile
	 * @return
	 */
	public static boolean validatePhoneNumber(String mobile) {
		Pattern p = Pattern.compile("^((13[0-9])|(12[0-9])|(19[0-9])|(16[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobile);
		return m.matches();
	}

	/**
	 *验证是否是中文
	 * @param str
	 * @return
	 */
	public static boolean isChineseChar(String str) {
		boolean temp = false;
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher m = p.matcher(str);
		if (m.find()) {
			temp = true;
		}
		return temp;
	}

	/**
	 *验证是否是数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str) {
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		}
		return true;
	}

	/**
	 * 是否十进制
	 * @param str
	 * @return
	 */
	public static boolean isDecimal(String str) {
		str = str.replaceAll("\\.", "");
		Pattern pattern2 = Pattern.compile("\\d+\\.\\d+$|-\\d+\\.\\d+$");
		Matcher isMather = pattern2.matcher(str);
		if (!isMather.matches()) {
			return false;
		}
		return true;
	}

	/**
	 * 验证是否是英语
	 * @param word
	 * @return
	 */
	public static boolean isEnglish(String word) {
		boolean sign = true;
		for (int i = 0; i < word.length(); i++) {
			if (!(word.charAt(i) >= 'A' && word.charAt(i) <= 'Z')
					&& !(word.charAt(i) >= 'a' && word.charAt(i) <= 'z')) {
				return false;
			}
		}
		return true;
	}

	/**
	 *
	 * @param str
	 * @return
	 */
	public static boolean repaceIsNumeric(String str) {
		String temp = str.replaceAll("-", "");
		boolean flag = isNumeric(temp);
		if (!flag) {
			temp = str.replaceAll("\\.", "");
			temp = temp.replaceAll("-", "");
			temp = temp.replaceAll("\\+", "");
			flag = isNumeric(temp);
			return flag;
		}
		return true;
	}

	/**
	 * 是否是邮箱
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email) {
		if (null == email || "".equals(email)) {
			return false;
		}
		Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");// 复杂匹配
		Matcher m = p.matcher(email);
		return m.matches();
	}

	/**
	 * 得到数字
	 * @param str
	 * @return
	 */
	public static String getNumberStr(String str){
		String regEx="[^0-9]";   
		Pattern p = Pattern.compile(regEx);   
		Matcher m = p.matcher(str);   
		String value = m.replaceAll("").trim();
		return value;
	}

	public static void main(String[] args) {
		System.out.println(RegUtil.repaceIsNumeric("15+"));
		System.out.println("15+".replaceAll("15+", ""));
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值