⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regexvalidator.java

📁 这个是使用java开发的一个平台
💻 JAVA
字号:
package com.exp.web.util.validator;

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

import com.exp.fcl.xml.EXPXMLNode;
import com.exp.web.util.FormBean;

public class RegexValidator extends BaseValidator {
    protected String regex = "";

    protected boolean bCaseInsensitive = false;

    protected void initConfig(EXPXMLNode validator) {
        this.regex = validator.getAttributeValue("regex");
        String temp = validator.getAttributeValue("case-insensitive");
        if (temp.equals("true")) {
            this.bCaseInsensitive = true;
        }
    }

    public boolean checkValid(FormBean formBean) {
        try {
            String value = formBean.getString(this.getTarget());
            if (this.bCaseInsensitive) {
                Pattern p = Pattern.compile(this.regex,
                        Pattern.CASE_INSENSITIVE);
                Matcher m = p.matcher(value);
                return m.matches();
            } else {
                Pattern p = Pattern.compile(this.regex);
                Matcher m = p.matcher(value);
                return m.matches();
            }
        } catch (Exception e) {
            return false;
        }
    }

    protected String genCheckCondition() {
        return this.matchRegExp(this.regex, this.bCaseInsensitive);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -