package sgc.portal.base.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * Websquare util.
 *
 * @author kkh
 * @version 2019.11.11
 * @since JDK1.8
 */
@Slf4j
public final class ValidChk {
    /**
     * Date check boolean.
     *
     * @param date   the date
     * @param format the format
     * @return the boolean
     */
    public static boolean dateCheck(String date, String format) {//날짜타입확인
        SimpleDateFormat dateFormatParser = new SimpleDateFormat(format, Locale.KOREA);
        dateFormatParser.setLenient(false);
        try {
            dateFormatParser.parse(date);
            return true;
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return false;
        }
    }

    /**
     * Is string double boolean.
     *
     * @param s the s
     * @return the boolean
     */
    public static boolean isStringDouble(String s) {//숫자체크
        if (StringUtils.isEmpty(s)) {
            return true;
        }
        try {
            Double.parseDouble(s);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * Is alpha num boolean.
     *
     * @param s the s
     * @return the boolean
     */
    public static boolean isAlphaNum(String s) {//특수문자 필터
        if (StringUtils.isEmpty(s)) {
            return true;
        }else{
            return s.matches("[0-9|a-z|A-Z|ㄱ-ㅎ|ㅏ-ㅣ|가-힝]*");
        }
    }
}
