All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swiftboot.web.validate.constraintvalidator.DecimalStringValidator Maven / Gradle / Ivy

There is a newer version: 2.4.7
Show newest version
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