package com.casic.missiles.util;

import org.apache.commons.lang.StringUtils;

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

/**
 * Created by test203 on 2019/5/23.
 */
public class RegUtil {


    public static boolean isDecimal2(String str) {// 判断小数点后2位的数字的正则表达式

        Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
//        Pattern pattern = Pattern.compile("^\\\\d{0,8}\\\\.{0,1}(\\\\d{1,2})?$");
        Matcher match = pattern.matcher(str);
        return match.matches();

    }

    public static boolean isNumOrLetter(String str) {// 判断字母或数字

        Pattern pattern = Pattern.compile("^\\w+$");
        Matcher match = pattern.matcher(str);
        return match.matches();

    }


    public static boolean isIp(String str) {// 判断iP
        if(StringUtils.isBlank(str)){
            return false;
        }

        Pattern pattern = Pattern.compile("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}");
        Matcher match = pattern.matcher(str);
        return match.matches();

    }

    public static boolean isPort(String str) {// 判断端口号
        if(StringUtils.isBlank(str)){
            return false;
        }
        Pattern pattern = Pattern.compile("^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]{1}|6553[0-5])$");
        Matcher match = pattern.matcher(str);
        return match.matches();

    }


    public static boolean isInteger(String str) {// 判断整数
        if(StringUtils.isBlank(str)){
            return false;
        }
        Pattern pattern = Pattern.compile("^[1-9]\\d*$");
        Matcher match = pattern.matcher(str);
        return match.matches();

    }


}
