ValidationRule

public class ValidationRule

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

  • the text field of the field

    Declaration

    Swift

    public var textField:UITextField
  • 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 text field, rules, and errorLabel.

    Declaration

    Swift

    public init(textField: UITextField, rules:[Rule], errorLabel:UILabel?)

    Parameters

    textField

    text field that holds actual text in text field.

    errorLabel

    label that holds error label of text field.

    rules

    array of Rule objects, which text 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 text field against its validation rules. - returns: ValidationError object if at least one error is found. Nil is returned if there are no validation errors.

    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.