Skip to content

Repository files navigation

Validator

Version Liscence Platform Swift4.2

Description

This library validate the string value in three rules: Regex, Length and Equality.

Example project

To run the example project, clone the repo, and run pod_reinstall.command from the Example directory first.

Usage

To use a Validator, all you need is to import 'Validator' module into your swift file:

import Validator

After that, you must select the required validation rule. To do this, the appropriate structures are used, all of them are inherited from the ValidationRule protocol.

1. Regex

For Regex rule you need to have regular expression string values and use RegexValidationRule struct.

// MARK: - Regex

enum Regex {
    static let email = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
    static let username = "^[a-zA-Z_]{1}[a-zA-Z0-9_]{2,18}$"
    static let password = "^[0-9a-zA-Z!@#$%^&*]{8,32}$"
}
/// Password text field
let passwordTextField: UITextField = {
    let passwordTextField = UITextField()
    passwordTextField.validateOnInputChange(enabled: true)
    return passwordTextField
}()

passwordTextField.add(rule: RegexValidationRule(pattern: Regex.password))

2. Length

For Length rule you need to use LengthValidationRule struct. You might use min, max or range length validation of strings.

/// Username text field
let usernameTextField: UITextField = {
    let usernameTextField = UITextField()
    usernameTextField.validateOnInputChange(enabled: true)
    return usernameTextField
}()

usernameTextField.add(rule: LengthValidationRule(min: 5))
usernameTextField.add(rule: LengthValidationRule(max: 20))
usernameTextField.add(rule: LengthValidationRule(min: 5, max: 20))

3. Equality

For Equality rule you need to use ConditionValidationRule or EqualityValidationRule structs.

Condition:
/// Condition text field
let conditionTextField: UITextField = {
    let conditionTextField = UITextField()
    conditionTextField.validateOnInputChange(enabled: true)
    return conditionTextField
}()

conditionTextField.add(rule: ConditionValidationRule { $0 == "target string" } )
Equality:
/// Equality text field
let equalityTextField: UITextField = {
    let equalityTextField = UITextField()
    equalityTextField.validateOnInputChange(enabled: true)
    return equalityTextField
}()

equalityTextField.add(rule: EqualityValidationRule { "target string" } )

Requirements

  • iOS 12.0+
  • Xcode 9.0
  • Swift 5.0

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

Cocoapods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To install it using CocoaPods, simply add the following line to your Podfile:

use_frameworks!

target "<Your Target Name>" do
pod "incetro-validator", :git => "https://github.com/Incetro/incetro-validator", :tag => "[0.0.3]"
end

Then, run the following command:

$ pod install

Manually

If you prefer not to use any dependency managers, you can integrate Validator into your project manually.

Embedded Framework

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:

    $ git init
  • Add Validator as a git submodule by running the following command:

    $ git submodule add https://github.com/incetro/incetro-validator.git
  • Open the new Validator folder, and drag the Validator.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the Validator.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different Validator.xcodeproj folders each with two different versions of the Validator.framework nested inside a Products folder.

  • Select the Validator.framework.

    You can verify which one you selected by inspecting the build log for your project. The build target for Nio will be listed as either Validator iOS.

  • And that's it!

    The Validator.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Authors

Gasol: 1ezya007@gmail.com, incetro: incetro@ya.ru

License

Validator is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages