Latest 2.0.0
Homepage https://github.com/3lvis/Validation
License MIT
Platforms ios 9.0, osx 10.9, watchos 2.0, tvos 9.0, requires ARC
Frameworks Foundation
Authors

A simple type to perform validations on Strings.

struct Validation {
    var minimumLength = 0
    var maximumLength: Int?
    var maximumValue: Double?
    var minimumValue: Double?
    var characterSet: CharacterSet?
    var format: String?
}

API

Making complete false will cause minimumLength, minimumValue and format to be ignored this is useful for partial validations, or validations where the final string is in process of been completed. For example when entering characters into an UITextField. With complete true all validations will be run.

func validateString(string: String, complete: Bool = true) -> Bool

Examples

Maximum or/and minimum length

var validation = Validation()
validation.minimumLength = 5
validation.maximumLength = 6

validation.validateString("1234") // => returns false
validation.validateString("12345") // => returns true
validation.validateString("1234567") // => returns false

Minimum or/and maximum value

var validation = Validation()
validation.minimumValue = 5
validation.maximumValue = 6

validation.validateString("4") // => returns false
validation.validateString("5") // => returns true
validation.validateString("7") // => returns false

NSCharacterSet

var validation = Validation()
validation.characterSet = NSCharacterSet.decimalDigitCharacterSet()

validation.validateString("23213") // => returns true
validation.validateString("hi there") // => returns false

Format (regex)

var validation = Validation()
validation.format = "[\w._%+-][email protected][\w.-]+\.\w{2,}"

validation.validateString("[email protected]") // => returns true
validation.validateString("elvnume.co") // => returns false
validation.validateString("hi there [email protected]") // => returns false

Installation

Validation is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Validation'

License

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

Author

Elvis Nuñez, @3lvis

Latest podspec

{
    "name": "Validation",
    "summary": "Validations for min/max value, min/max length, regex and so on",
    "version": "2.0.0",
    "homepage": "https://github.com/3lvis/Validation",
    "license": "MIT",
    "authors": {
        "Elvis Nuu00f1ez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/3lvis/Validation.git",
        "tag": "2.0.0"
    },
    "social_media_url": "https://twitter.com/3lvis",
    "platforms": {
        "ios": "9.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*",
    "frameworks": "Foundation",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This