Contents

palmeiralabs/inputfence

InputFence is a lightweight and flexible Swift Package designed to simplify user input validation in any iOS, macOS, watchOS, or tvOS application.

✨ Features

  • βœ… Prebuilt Validators – Quickly validate common input types.
  • βš™οΈ Configurable Parameters – Adjust rules such as min/max lengths, allowed characters, and age ranges.
  • πŸ›  Protocol-Oriented Design – Easy to extend and create your own custom validators.
  • πŸ“¦ Swift Package Manager Support – Simple integration into any project.
  • 🌍 Locale-Aware – Handles formats like date of birth parsing with regional settings.

πŸ“¦ Installation

Swift Package Manager

  1. In Xcode, go to File > Add Packages...
  2. Enter the repository URL:

`` https://github.com/PalmeiraLabs/InputFence ``

  1. Select the version and add it to your project.

πŸš€ Usage

Example – Validating a Date of Birth

import InputFence

let validator = AdvancedDateOfBirthValidator(
    parameters: DateOfBirthValidatorParameters(minAge: 18, maxAge: 99)
)

if validator.isValid("12/08/1995") {
    print("Valid date of birth βœ…")
} else {
    print("Invalid date of birth ❌")
}

Example – Validating a Username

import InputFence

let validator = UsernameValidator(
    parameters: UsernameValidatorParameters(minLength: 3, maxLength: 20)
)

if validator.isValid("Agustin") {
    print("Valid username βœ…")
} else {
    print("Invalid username ❌")
}

Usage examples

import InputFence

// Example 1: Validate an email using the simple validator
let emailValidator = SimpleEmailValidator()
print(emailValidator.isValid("user@example.com")) // true
print(emailValidator.isValid("invalid-email"))    // false

// Example 2: Use an advanced password validator with custom parameters
let passwordParams = PasswordValidatorParameters(
    minLength: 8,
    requireUppercase: true,
    requireNumber: true,
    requireSpecialCharacter: true
)
let passwordValidator = AdvancedPasswordValidator(parameters: passwordParams)
print(passwordValidator.isValid("P@ssword1")) // true

// Example 3: Use the generic wrapper to validate a field
let wrappedEmail = EmailValidator(
    validator: SimpleEmailValidator(),
    value: "contact@domain.com"
)
print(wrappedEmail.isValid()) // true

// Example 4: Use the generic wrapper to validate passwords
let wrappedPassword = PasswordValidator(
    validator: passwordValidator,
    value: "1234"
)
print(wrappedPassword.isValid()) // false

Tips

  • You can instantiate a specific validator directly (e.g., SimpleEmailValidator().isValid(...)).
  • You can wrap a specific validator inside your generic FieldValidator (e.g., EmailValidator(...) or PasswordValidator(...)).
  • You can pass custom parameters (as in AdvancedPasswordValidator).
  • FieldValidator<T> β†’ Generic that accepts any validation protocol implementation.
  • Typealiases (EmailValidator, PasswordValidator, etc.) β†’ Typed versions for each data type.
  • Protocols (EmailValidatorProtocol, etc.) β†’ Define the validation rules.
  • Concrete implementations (SimpleEmailValidator, AdvancedPasswordValidator, etc.) β†’ Actual validation logic.

πŸ“š Documentation

For detailed guides, API reference, and validator specifications, check out the full documentation:

1. Clone this repository. 2. Install MkDocs (if you don’t have it): ``bash pip install mkdocs-material ` 3. Serve the documentation locally: `bash mkdocs serve ` 4. Open http://127.0.0.1:8000` in your browser.

Documentation source files are located in the docs/ directory and include:

  • Validators β†’ Usage of each built-in validator.
  • Protocols β†’ Interfaces and extension points.
  • Parameters β†’ Customization and configuration options.

πŸ“„ License

This project is licensed under the MIT License – see the LICENSE file for details.

Author

Agustin Palmeira / PalmeiraLabs

πŸ“¬ Contact

Feel free to reach out with questions, feedback, or licensing inquiries:

πŸ“§ agustin.palmeira.it@gmail.com πŸ”— https://www.linkedin.com/in/agustin-daniel-palmeira/

Package Metadata

Repository: palmeiralabs/inputfence

Default branch: main

README: README.md