package com.hfkj.common.utils;

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

/**
 *  
 * @ClassName:  FormatValidateUtil   
 * @Description:TODO(格式校验)   
 * @author: 胡锐 
 * @date:   2018年8月2日 上午10:12:43   
 *     
 * @Copyright: 2018 www.shinwoten.com Inc. All rights reserved.
 */
public class MemberValidateUtil {
	
	/**
	 * 
	 * @Title: validateName   
	 * @Description: TODO(用户名验证) 
	 * @author: 胡锐 
	 * @param: @param name
	 * @param: @return      
	 * @return: boolean      
	 * @throws
	 */
	public static boolean validateName(String name) {
		 if(name.length() < 2 || name.length() > 20) {
			 return false;
		 }
		
		 return true;
	}
	
	/**
	 * 
	 * @Title: validatePhone   
	 * @Description: TODO(手机号格式校验) 
	 * @author: 胡锐 
	 * @param: @param phone
	 * @param: @return      
	 * @return: boolean      
	 * @throws
	 */
	public static boolean validatePhone(String phone) {
		phone = replaceBlank(phone);
		String regex = "^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(phone);
        boolean isMatch = m.matches();
        return isMatch;
	}
	
	
	/**
	 * 
	 * @Title: validatePass   
	 * @Description: TODO(密码格式校验) 
	 * @author: 胡锐 
	 * @param: @param password
	 * @param: @return      
	 * @return: boolean      
	 * @throws
	 */
	public static boolean validatePass(String password) {
		String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
		Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(password);
        boolean isMatch = m.matches();
        return isMatch;
            
	}
	
	/**
	 * 
	 * @Title: validatePass   
	 * @Description: TODO(校验身份证) 
	 * @author: 胡锐 
	 * @param: @param password
	 * @param: @return      
	 * @return: boolean      
	 * @throws
	 */
	public static boolean validateIdCard(String idCard) {
		String regex = "(^\\\\d{18}$)|(^\\\\d{15}$)";
        return Pattern.matches(regex,idCard);
	}

	public static boolean isNumber(String str) {
		Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判断小数点后2位的数字的正则表达式
		Matcher match = pattern.matcher(str);
		if (match.matches() == false) {
			return false;
		} else {
			return true;
		}
	}

	public static String replaceBlank(String str) {
		String dest = "";
		if (str!=null) {
			Pattern p = Pattern.compile("\\s*|\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}

	public static void main(String[] args) throws Exception {
		System.out.println(validatePhone("15983795288"));
	}
}
