InRangeValidation

public protocol InRangeValidation: Validation where Supported: Comparable

A validation for checking that a value is greater or equal to a lesser value and less than or equal to a greater value.

struct NumberThousand: InRangeValidation {
    static let max: Int? = 9_999
    static let min: Int? = 1_000
}

If the value being validated is greater than the max value, ValidationError.valueTooGreat is throw. If the value is less than the min value, ValidationError.valueTooSmall is thrown.

If the max or min value is nil, then the value being validated will not be checked against it. This allows for one sided validation ranges, where you could, for example, have any number greater than 42.

  • max

    The maximum value that the value being validated could be.

    This property defaults to nil.

    Declaration

    Swift

    static var max: Supported?
  • min

    The miniumum value that the value being validated could be.

    This property defaults to nil.

    Declaration

    Swift

    static var min: Supported?