List of usage examples for org.apache.commons.validator.routines PercentValidator getInstance
public static BigDecimalValidator getInstance()
From source file:com.iana.boesc.utility.BOESCUtil.java
/** * Validates whether data provided is in percentage or not * // www. java2s. c o m * @param percentVal * @return */ public static boolean percentValidator(String percentVal) { BigDecimalValidator validator = PercentValidator.getInstance(); boolean valid = false; BigDecimal Percent = validator.validate(percentVal, Locale.US); if (Percent == null) { valid = false; } // Check the percent is between 0% and 100% if (validator.isInRange(Percent, 0, 1)) { valid = true; } else { valid = false; } return valid; }
From source file:org.mule.modules.validation.ValidationModule.java
/** * If the specified <code>percentage</code> is not a valid one throw an exception. * <p/>//w w w.java 2 s. c om * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-percentage} * * @param percentage Percentage to validate * @param customExceptionClassName Class name of the exception to throw * @throws Exception if not valid */ @Processor public void validatePercentage(String percentage, @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName) throws Exception { BigDecimalValidator validator = PercentValidator.getInstance(); if (!validator.isValid(percentage)) { throw buildException(customExceptionClassName); } }