TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Elvis Nuñez.
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?
}
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
var validation = Validation()
validation.minimumLength = 5
validation.maximumLength = 6
validation.validateString("1234") // => returns false
validation.validateString("12345") // => returns true
validation.validateString("1234567") // => returns false
var validation = Validation()
validation.minimumValue = 5
validation.maximumValue = 6
validation.validateString("4") // => returns false
validation.validateString("5") // => returns true
validation.validateString("7") // => returns false
var validation = Validation()
validation.characterSet = NSCharacterSet.decimalDigitCharacterSet()
validation.validateString("23213") // => returns true
validation.validateString("hi there") // => returns false
var validation = Validation()
validation.format = "[\\w._%+-]+@[\\w.-]+\\.\\w{2,}"
validation.validateString("[email protected]") // => returns true
validation.validateString("elvnume.co") // => returns false
validation.validateString("hi there [email protected]") // => returns false
Validation is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'Validation'
Validation is available under the MIT license. See the LICENSE file for more info.
Elvis Nuñez, @3lvis