package com.sysu.admin.utils;

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


/**
 * 表单验证工具类
 * @author 86137
 *
 */
public class CheckUtil {
	
	
	/**
	 * 验证是不是数字
	 * @param text
	 * @return
	 */
	public static boolean isNumber(String text) {
		if(text == null || text.length() == 0) {
			return false;
		}
		int i = text.length() - 1;
		while(i > -1) {
			int c = text.charAt(i);
			if(c  < '0' || c > '9' ) {
				return false;
			}
			i--;
		}
		return true;
	}
	
	public static void main(String[] args) {
		System.out.println();
	}
	
	
	/**
	 * 验证不为null 或 ""  或 "    "
	 * @param text
	 * @return
	 */
	public static boolean notNull(String text) {
		if(text == null || text.trim().equals("")) {
			return  false;
		}
		return true;
	}
	
	public static boolean isPhone(String phone) {
		String regex = "^((13[0-9])|(14[0-9])|(15([0-9]))|(16([0-9]))|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";
		if (phone.length() != 11) {
//			System.out.println("手机号应为11位数");
			return false;
		}
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(phone);
		boolean isMatch = m.matches();
		if (isMatch) {
//			System.out.println("您的手机号" + phone + "是正确格式@——@");
			return true;
		} else {
//			System.out.println("您的手机号" + phone + "是错误格式！！！");
			return false;
		}
	}

	public static boolean isEmail(String email) {
		String regex = "^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(email);
		boolean isMatch = m.matches();
		if (isMatch) {
//			System.out.println("您的手机号" + phone + "是正确格式@——@");
			return true;
		} else {
//			System.out.println("您的手机号" + phone + "是错误格式！！！");
			return false;
		}
	}
	
}
