ValidationRule

public class ValidationRule

ValidationRule is a class that creates an object which holds validation info of a field.

  • the field of the field

    Declaration

    Swift

    public var field:ValidatableField
  • the errorLabel of the field

    Declaration

    Swift

    public var errorLabel:UILabel?
  • the rules of the field

    Declaration

    Swift

    public var rules:[Rule] = []
  • Initializes ValidationRule instance with field, rules, and errorLabel.

    Declaration

    Swift

    public init(field: ValidatableField, rules:[Rule], errorLabel:UILabel?)

    Parameters

    field

    field that holds actual text in field.

    errorLabel

    label that holds error label of field.

    rules

    array of Rule objects, which field will be validated against.

    Return Value

    An initialized ValidationRule object, or nil if an object could not be created for some reason that would not result in an exception.

  • Used to validate field against its validation rules.

    Declaration

    Swift

    public func validateField() -> ValidationError?

    Return Value

    ValidationError object if at least one error is found. Nil is returned if there are no validation errors.