SwiftValidator
Swift Validator is a rule-based validation library for Swift.
Core Concepts
UITextField
+[Rule]
+ (and optional errorUILabel
) go intoValidator
UITextField
+ValidationError
come out ofValidator
Validator
evaluates[Rule]
sequentially and stops evaluating when aRule
fails.
Installation
Install into your project:
Open your project in Xcode from the .xcworkspace file (not the usual project file):
If you are using Carthage you will need to add this to your Cartfile
Usage
You can now import SwiftValidator framework into your files.
Initialize the Validator
by setting a delegate to a View Controller or other object.
Register the fields that you want to validate
Validate Fields on button tap or however you would like to trigger it.
Implement the Validation Delegate in your View controller
Single Field Validation
You may use single field validation in some cases. This could be useful in situations such as controlling responders:
Custom Validation
We will create a SSNRule
class to show how to create your own Validation. A United States Social Security Number (or SSN) is a field that consists of XXX-XX-XXXX.
Create a class that inherits from RegexRule
Documentation
Checkout the docs here via @jazzydocs.
Credits
Swift Validator is written and maintained by Jeff Potter @jpotts18. David Patterson @dave_tw12 actively works as a collaborator. Special thanks to Deniz Adalar for
adding validation beyond UITextField.
Contributing
- Fork it
- Create your feature branch
git checkout -b my-new-feature
- Commit your changes
git commit -am 'Add some feature'
- Push to the branch
git push origin my-new-feature
- Create a new Pull Request
- Make sure code coverage is at least 70%