FloatValidator

public class FloatValidator extends BaseValidator implements GracieValidator{
    
    public FloatValidator() {
        
    }

    public static final String REGEX_FLOAT = "^(-?\\d+)(\\.\\d{1,2})?$";
    
    /**
     * Validation Rule: A number that the MAX digits after the decimal is 2.
     * @param inputText          Input string text
     * @return boolean           Return true when input string is only composed by subtraction sign and a number that the MAX digits after the decimal is 2,
     *                           otherwise return false.
     */    
    public static boolean isFloat(String inputText) {
        return RegexValidator.isValid(FloatValidator.REGEX_FLOAT, inputText);
    }
    
    /**
     * Validation Rule: A number that the MAX digits after the decimal is 2.
     * @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 subtraction sign and a number that the MAX digits after the decimal is 2,
     *                           otherwise return false.
     */    
    public static boolean isFloat(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = FloatValidator.isFloat(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number that the MAX digits after the decimal is 2.
     * @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 subtraction sign and a number that the MAX digits after the decimal is 2,
     *                           otherwise return false.
     */    
    public static boolean isFloat(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = FloatValidator.isFloat(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }

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

	public boolean isValid(String inputText, String fieldErrorParam, String fieldErrorMessage) {
		return FloatValidator.isFloat(inputText, fieldErrorParam, fieldErrorMessage);
	}

	public boolean isValid(String inputText) {
		return FloatValidator.isFloat(inputText);
	}
    
	public boolean isValid(String inputText, Object[] objs) {
		return isValid(inputText);
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值