在各自岗位上尽职尽责,无需豪言壮语,默默行动会诠释一切。这世界,虽然没有绝对的公平,但是努力就会增加成功和变好的可能性!而这带着未知变量的可能性,就足以让我们普通人拼命去争取了。
欢迎来到~一支会记忆的笔~博客主页

正则表达式工具类,验证数据是否符合规范

package com.JUtils.base;

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

/**
 * 正则表达式工具类,验证数据是否符合规范
 *
 */
public class RegexUtils {
    
    /**
     * 判断字符串是否符合正则表达式
     *
     * @param str
     * @param regex
     * @return
     */
    public static boolean find(String str, String regex) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean b = m.find();
        return b;
    }
    
    /**
     * 判断输入的字符串是否符合Email格式.
     *
     * @param email
     *                 传入的字符串
     * @return 符合Email格式返回true,否则返回false
     */
    public static boolean isEmail(String email) {
        if (email == null || email.length() < 1 || email.length() > 256) {
            return false;
        }
        Pattern pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
        return pattern.matcher(email).matches();
    }
    
    /**
     * 判断输入的字符串是否为纯汉字
     *
     * @param value
     *                 传入的字符串
     * @return
     */
    public static boolean isChinese(String value) {
        Pattern pattern = Pattern.compile("[\u0391-\uFFE5]+$");
        return pattern.matcher(value).matches();
    }
    
    /**
     * 判断是否为浮点数,包括double和float
     *
     * @param value
     *             传入的字符串
     * @return
     */
    public static boolean isDouble(String value) {
        Pattern pattern = Pattern.compile("^[-\\+]?\\d+\\.\\d+$");
        return pattern.matcher(value).matches();
    }
    
    /**
     * 判断是否为整数
     *
     * @param value
     *             传入的字符串
     * @return
     */
    public static boolean isInteger(String value) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]+$");
        return pattern.matcher(value).matches();
    }
}

 

posted @ 2019-07-31 15:30  一支会记忆的笔  阅读(1108)  评论(0编辑  收藏  举报
返回顶部
【学无止境❤️谦卑而行】