StringInputValidator provides a convenient way to test a given string against a validator. A validator can be as simple the RegularExpressionValidator.numeric which checks wether the string contains numeric values only. Or a complex validator if you combine length/format validation using a composite validator.
let lengthVal = LengthValidator(lengthLimit: 5)
let emptyVal = NotEmptyValidator()
let numVal = RegularExpressionValidator.numeric
let compVal = CompositeValidator(validators: lengthVal, emptyVal, numVal)
let res = compVal.validate(value: "absdefgh")
// ask for validity
res.isValid()
// or
if case let .invalid(error) = res {
error.contains(.invalidFormat)
error.contains(.lengthExceeded)
} else {}
// check the description [InvalidFormat, LengthExceeded, LengthMismatch]
let string = error.description
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate StringInputValidator into your Xcode project using Carthage, specify it in your Cartfile
:
github "HHuckebein/StringInputValidator"
Run carthage
to build the framework and drag the built StringInputValidator.framework
into your Xcode project.
RABE_IT Services, [email protected]
StringInputValidator is available under the MIT license. See the LICENSE file for more info.