`

DigitValidator

阅读更多
public class DigitValidator extends BaseValidator implements GracieValidator {
    
    public DigitValidator() {
        
    }
    
    public static final String REGEX_DIGIT = "^[0-9]+$";
    
    /**
     * Validation Rule: Only to accept "0-9"
     * @param inputText          Input string text
     * @return boolean           Return true when input string is only composed by "0-9" digit,
     *                           otherwise return false.
     */    
    public static boolean isDigit(String inputText) {
        return RegexValidator.isValid(DigitValidator.REGEX_DIGIT, inputText);
    }
    
    /**
     * Validation Rule: Only to accept "0-9"
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is only composed by "0-9" digit,
     *                           otherwise return false.
     */    
    public static boolean isDigit(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = DigitValidator.isDigit(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: Only to accept "0-9"
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is only composed by "0-9" digit,
     *                           otherwise return false.
     */    
    public static boolean isDigit(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = DigitValidator.isDigit(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
	public boolean isValid(String inputText) {
		return DigitValidator.isDigit(inputText);
	}

	public boolean isValid(String inputText, String fieldErrorParam, String bundle, String key, String defaultMessage, String[] arguments) {
		return DigitValidator.isDigit(inputText, fieldErrorParam, bundle, key, defaultMessage, arguments);
	}

	public boolean isValid(String inputText, String fieldErrorParam, String fieldErrorMessage) {
		return DigitValidator.isDigit(inputText, fieldErrorParam, fieldErrorMessage);
	}
	
	public boolean isValid(String inputText, Object[] objs) {
		return isValid(inputText);
	}

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics