package com.dsk.common.utils;

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

/**
 * 邮箱和手机号验证
 */
public class CheckUtils {

    public static final String REG_Moblie = "^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\\d{8}$";

    public static final String REG_EMAIL = "[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+";

    /**
     * 校验email
     * @param email
     * @return
     */
    public static boolean isEmail(String email){
        if (email == null){
            return false;
        }else {
            boolean isMatch = Pattern.matches(REG_EMAIL,email);
            return isMatch;
        }
    }

    /**
     * 校验手机号
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone){
        if (phone == null){
            return false;
        }else {
            Pattern p = Pattern.compile(REG_Moblie);
            Matcher m = p.matcher(phone);
            return m.matches();
        }

    }
}
