字符串相关

来源:互联网 发布:随州广电网络 编辑:程序博客网 时间:2024/04/30 00:51
 /**     * 功能:判断字符串是否为数字     *      * @param str     * @return     */    private static boolean isNumeric(String str) {    try {    Pattern pattern = Pattern.compile("[0-9]*");            Matcher isNum = pattern.matcher(str);            if (isNum.matches()) {                return true;            } else {                return false;            }} catch (Exception e) {return false;}            }    /**     * 功能:判断字符串是否为日期格式     *      * @param str     * @return     */    public static boolean isDate(String strDate) {    try {    Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");            Matcher m = pattern.matcher(strDate);            if (m.matches()) {                return true;            } else {                return false;            }} catch (Exception e) {return false;}    }

0 0
原创粉丝点击