package com.community.commom.utils;

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

/**
 * 校验类
 * @author weiximei
 */
public class AccountValidatorUtil {

    /**
     * 校验手机号
     * @param phone
     * @return
     */
        public static boolean isPhone(String phone) {
            String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
            if (phone.length() != 11) {
                //MToast.showToast("手机号应为11位数");
                return false;
            } else {
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(phone);
                boolean isMatch = m.matches();
                if (!isMatch) {
                    //MToast.showToast("请填入正确的手机号");
                }
                return isMatch;
            }
        }


    /**
     * 校验座机号
     * @param phone
     * @return
     */
    public static boolean isLandline(String phone) {
        String regex = "/^(\\d{3}-)(\\d{8})$|^(\\d{4}-)(\\d{7})$|^(\\d{4}-)(\\d{8})$/";
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            if (!isMatch) {
                //MToast.showToast("请填入正确的手机号");
            }
            return isMatch;
    }

    /**
     * 校验是否全为数字
     * @param str
     * @return
     */
    public static boolean isNumber(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    public static void main(String[] args) {
        System.out.println(isNumber("1"));
    }

}
