This library validate the string value in three rules: Regex, Length and Equality.
To run the example project, clone the repo, and run pod_reinstall.command from the Example directory first.
To use a Validator, all you need is to import 'Validator' module into your swift file:
import ValidatorAfter 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.
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))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))For Equality rule you need to use ConditionValidationRule or EqualityValidationRule structs.
/// Condition text field
let conditionTextField: UITextField = {
let conditionTextField = UITextField()
conditionTextField.validateOnInputChange(enabled: true)
return conditionTextField
}()
conditionTextField.add(rule: ConditionValidationRule { $0 == "target string" } )/// Equality text field
let equalityTextField: UITextField = {
let equalityTextField = UITextField()
equalityTextField.validateOnInputChange(enabled: true)
return equalityTextField
}()
equalityTextField.add(rule: EqualityValidationRule { "target string" } )- iOS 12.0+
- Xcode 9.0
- Swift 5.0
- 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.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapodsTo 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]"
endThen, run the following command:
$ pod installIf you prefer not to use any dependency managers, you can integrate Validator into your project manually.
-
Open up Terminal,
cdinto 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
Validatorfolder, and drag theValidator.xcodeprojinto 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.xcodeprojin 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.xcodeprojfolders each with two different versions of theValidator.frameworknested inside aProductsfolder. -
Select the
Validator.framework.You can verify which one you selected by inspecting the build log for your project. The build target for
Niowill be listed as eitherValidator iOS. -
And that's it!
The
Validator.frameworkis 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.
Gasol: 1ezya007@gmail.com, incetro: incetro@ya.ru
Validator is available under the MIT license. See the LICENSE file for more info.
