Class NumberValidationRule

  • All Implemented Interfaces:
    ValidationRule

    public class NumberValidationRule
    extends BaseValidationRule
    A validator performs syntax and possibly semantic validation of a single piece of data from an untrusted source.
    Since:
    June 1, 2007
    Author:
    Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
    See Also:
    Validator
    • Constructor Detail

      • NumberValidationRule

        public NumberValidationRule​(java.lang.String typeName,
                                    Encoder encoder)
      • NumberValidationRule

        public NumberValidationRule​(java.lang.String typeName,
                                    Encoder encoder,
                                    double minValue,
                                    double maxValue)
    • Method Detail

      • getValid

        public java.lang.Double getValid​(java.lang.String context,
                                         java.lang.String input)
                                  throws ValidationException
        Parse the input, throw exceptions if validation fails
        Parameters:
        context - for logging
        input - the value to be parsed
        Returns:
        a validated value
        Throws:
        ValidationException - if any validation rules fail
      • sanitize

        public java.lang.Double sanitize​(java.lang.String context,
                                         java.lang.String input)
        The method is similar to ValidationRuile.getSafe except that it returns a harmless object that may or may not have any similarity to the original input (in some cases you may not care). In most cases this should be the same as the getSafe method only instead of throwing an exception, return some default value.
        Specified by:
        sanitize in class BaseValidationRule
        Returns:
        a parsed version of the input or a default value.