Swiftpack.co - Package - smbhuin/SBValidator

SBValidator

Rule based validation library for swift.

Platform Carthage Compatible SPM Compatible LICENSE

Features

  • Rule based validation
  • Class/Struct validation
  • JSON validation
  • Validatable/Validator chaining
  • Linux Compatible (Can be used with Kitura, Vapor, Perfect)

iPhone Screenshot

Screenshot

Installation

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

Carthage

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.

CocoaPods

You can use CocoaPods.

platform :ios, '10.0'
use_frameworks!

target 'MyApp' do
pod 'SBValidator'
end

or for newest version from specified branch of code:

pod 'SBValidator', :git => "https://github.com/smbhuin/SBValidator", :branch => "master"

Swift Package Manager

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"))
]

Usage

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)
}

Validation Rules

| 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. |

API documentation

For more information visit our API reference.

Credits

Thanks to SwiftValidator

License

This library is licensed under MIT. Full license text is available in LICENSE.

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

Release 3.0.0 - 2020-05-15 05:11:54

Added

  • CurrencyRule added.
  • NumericRule added.
  • errorOnValidate method added in Validator
  • firstValid method added in Validator
  • firstInvalid method added in Validator

Updated

  • PhoneNumberRule updated. You can now specify the Format of phone number.

Breaking Changes

  • validate() method now throws exception and returns Bool
  • validate(named: String) method now throws exception and returns Bool
  • validateAll() method now returns [ValidationError]?

Previous validate() -> (valid: Bool, validatable: NamedValidatable?, error: ValidationError?) Now validate() throws -> Bool

Release 2.0.1 - 2020-02-12 16:49:54

Renamed

  • func month renamed to var month in MonthRule extension.

Updated

  • ArrayLengthRule changed to generic from Any type.

Release 2.0.0 - 2020-01-07 09:34:05

Renamed

  • Framework renamed.
  • Cocoapod framework renamed to SBValidator.

Release 1.0.5 - 2019-12-12 07:21:21

Updated

  • ArrayRule updated.

Release 1.0.4 - 2019-07-31 17:29:19

Updated

  • Package restructured.
  • XCode Project Config Updated.
  • Cocoapod Spec Updated.

Renamed

  • var ISBN renamed to isbn in ISBNRule.
  • var IPV4 renamed to ipv4 in IPV4Rule.
  • var iso8601date renamed to iso8601Date in ISO8601DateRule.

Release 1.0.3 - 2019-07-28 09:15:35

Updated

  • Fixes for cocoapod.

Stable Release 1.0.2 - 2019-07-28 09:01:42

Updated

  • Fixes for cocoapod.

Stable Release 1.0.1 - 2019-07-28 07:45:22

Updated

  • Validator functions return named touples now.

Initial Release - 2019-07-27 18:48:58

  • Initial release of Validator.