
org.swiftboot.web.validate.constraintvalidator.DecimalStringValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swiftboot-web Show documentation
Show all versions of swiftboot-web Show documentation
Basic module for enterprise web applications
package org.swiftboot.web.validate.constraintvalidator;
import org.apache.commons.lang3.StringUtils;
import org.swiftboot.web.validate.constraint.DecimalString;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* @author swiftech
* @since 1.2
*/
public class DecimalStringValidator implements ConstraintValidator {
private DecimalString onlyNumber;
@Override
public void initialize(DecimalString constraintAnnotation) {
this.onlyNumber = constraintAnnotation;
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
// this validator doesn't validate 'null' value
return value == null || (StringUtils.isNotBlank(value) && value.matches("^[0-9]*\\.?[0-9]*$"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy