DSValidationRule

public protocol DSValidationRule

Represents a validation of text entered into a DSTextField.

Validation rules are added to DSTextField as follows:

let textField = DSTextField()

textField.add(validationRule: DSMaxTextLengthValidationRule(maxTextLength: 50, message: "Text too long."))

All validation rules, and any you create, should accept empty text as valid. This is so new forms don’t show errors on all required fields right away. Once a form element is interacted with (didBeginEditing), you can then add a DSRequiredTextValidationRule so that if the field data is cleared it will display an error properly. Be careful to only add this rule once although there will be no issues if you do duplicate them. You can also call removeAllValidationRules if you want to reset everything.

  • The error message to display if invalid.

    Declaration

    Swift

    var errorMessage: String { get }
  • Returns true if the text is validated by this rule.

    Declaration

    Swift

    func isValid(_ text: String) -> Bool