Rule based validation library for swift.
- Rule based validation
- Class/Struct validation
- JSON validation
- Validatable/Validator chaining
- Linux Compatible (Can be used with Kitura, Vapor, Perfect)
To install Validator, add it as a submodule to your project (on the top level project directory):
git submodule add https://github.com/smbhuin/SBValidator.git
You can use Carthage. Specify in Cartfile:
github "smbhuin/SBValidator"Run carthage to build the framework and drag the built SBValidator.framework into your Xcode project. Follow build instructions.
You can use CocoaPods.
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'SBValidator'
endor for newest version from specified branch of code:
pod 'SBValidator', :git => "https://github.com/smbhuin/SBValidator", :branch => "master"You can use Swift Package Manager and specify dependency in Package.swift by adding this:
dependencies: [
.package(url: "https://github.com/smbhuin/SBValidator.git", from: "3.0.0")
]or more strict
dependencies: [
.package(url: "https://github.com/smbhuin/SBValidator.git", .exact("3.0.0"))
]import SBValidator
let v = Validator()
v.add(name: "Email", value: email, rules: [.required, .email])
v.add(name: "Name", value: name, rules: [.required, .fullName])
v.add(name: "Subject", value: subject, rules: [.required, .length(min: 10, max: 200)])
v.add(name: "Message", value: message, rules: [.required, .length(min: 10, max: 2000)])
do {
try v.validate()
} catch {
debugPrint(error)
}| Rules | Description |
|---|---|
| AlphaNumericRule | Only Alpha Numeric characters are allowed. |
| AlphaRule | Only Alpha characters are allowed. |
| ArrayLengthRule | Puts a limit on array length. |
| ArrayRule | Apply rules on each element of array. |
| CharacterSetRule | Provides set of characters to be allowed. |
| ConfirmRule | Match with specific value. |
| CoordinateRule | Takes latitude and longitude as [Double] and validates. |
| CurrencyRule | Takes currency as String and validates. |
| DateRule | Takes date as String and validates. |
| EmailRule | Checks for valid email. |
| EnumRule | Checks against a set of values. |
| ExactLengthRule | Checks for fixed length of String |
| FloatRule | Check for valid floating point number as String |
| FullNameRule | Checks for full name of a person. |
| HexColorRule | Validates hex color code. |
| IPV4Rule | Checks for IP v4. |
| ISBNRule | Checks for valid ISBN number. |
| ISO8601DateRule | Checks for Date String in IOS8601 format. |
| LengthRule | Checks for minimun and maximum length provided. |
| MonthRule | Checks for valid month number (01 to 12) |
| NumericRule | Checks for decimal degits only. |
| PasswordRule | Checks for password of desired strength. |
| PhoneNumberRule | Checks for valid phone number. |
| PinCodeRule | Checks for valid indian pin code. |
| RangeRule | Checks against minimum and maximum value provided. |
| RegexRule | Checks against regular expression provided. |
| RequiredRule | Checks if it has value, not nil or empty |
| ValidatableRule | For struct or object validation. |
| YearExpiryRule | Validates credit/debit card's expiry year. |
| ZipCodeRule | Checks for valid zip code. |
For more information visit our API reference.
Thanks to SwiftValidator
This library is licensed under MIT. Full license text is available in LICENSE.
