defaultvalidator.java

来自「一个自己做的公司网站和办公职员管理系统。」· Java 代码 · 共 95 行

JAVA
95
字号
package ws.woa.util;

/**
 * NULL僠僃僢僋丄宆僠僃僢僋丄僶僀僩悢僠僃僢僋傪峴偆僶儕僨乕僞丅
 *
 * @author Wang
 */
public class DefaultValidator implements Validator {

    public static final int STRING  = 0;
    public static final int NUMERIC = 1;
    public static final int ASCII   = 2;
    public static final int ALPHA   = 3;
    public static final int ALPHA_NUMERIC = 4;

    private int type;
    private int length = 0;
    private boolean notNull;

    /**
     * @param type 宆
     */
    public DefaultValidator(int type){
        this(type,0);
    }

    /**
     * @param type 宆
     * @param length 嵟戝僶僀僩悢
     */
    public DefaultValidator(int type,int length){
        this(type,length,false);
    }

    /**
     * @param type 宆
     * @param notNull 昁恵偐偳偆偐
     */
    public DefaultValidator(int type,boolean notNull){
        this(type,0,notNull);
    }

    /**
     * @param type 宆
     * @param length 嵟戝僶僀僩挿
     * @param notNull 昁恵偐偳偆偐
     */
    public DefaultValidator(int type,int length,boolean notNull){
        this.type = type;
        this.length = length;
        this.notNull = notNull;
    }

    /**
     * 堷悢偱搉偝傟偨僷儔儊乕僞偺専徹傪峴偄傑偡丅
     *
     * @param param 僷儔儊乕僞
     * @return 惓偟偄応崌true丄晄惓側応崌false丅
     */
    public boolean doValidate(String param){
        // NULL僠僃僢僋
        if(this.notNull){
            if(!CheckUtil.nullCheck(param)){
                return false;
            }
        }
        // 僶僀僩悢偺僠僃僢僋
        if(length>0){
            if(param!=null && !CheckUtil.bytesCheck(param,length)){
                return false;
            }
        }

        // 宆偺僠僃僢僋
        if(this.type==NUMERIC){ // 悢抣
            if(param!=null && !CheckUtil.numericCheck(param)){
                return false;
            }
        } else if(this.type==ASCII){ // 傾僗僉乕
            if(param!=null && !CheckUtil.asciiCheck(param)){
                return false;
            }
        } else if(this.type==ALPHA){ // 敿妏傾儖僼傽儀僢僩
            if(param!=null && !CheckUtil.alphaCheck(param)){
                return false;
            }
        } else if(this.type==ALPHA_NUMERIC){ // 敿妏傾儖僼傽儀僢僩偲敿妏悢帤
            if(param!=null && !CheckUtil.alphaNumericCheck(param)){
                return false;
            }
        }
        return true;
    }
}

⌨️ 快捷键说明

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