TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2016 |
SPMSupports SPM | ✗ |
Maintained by Ysee Monnier.
TextField Validation library for Swift (@IBDesignable & Programmatically)
First create your custom validator class. The class has to have @objc
declaration, conform to YMRulesValidator
protocol and NSObject
.
@objc(EmailValidator)
class EmailValidator: NSObject, YMRulesValidator {
var regex: String = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
}
YMValidator
Class Name
and Error Message
YMValidator
@IBOutlet weak var errorEmailLabel: UILabel!
@IBOutlet weak var inputEmail: YMValidator!
override func viewDidLoad() {
super.viewDidLoad()
self.errorEmailLabel.text = ""
self.inputEmail.setErrorLabel(self.errorEmailLabel)
}
//ViewController.swift
let textField = YMValidator(frame: CGRect(x: 30.0, y: 296.0, width: 540, height: 30), rulesValidator: CustomValidator(), errorMessage: "Only alphanumeric characters are allowed", errorLabel: customErrorLabel)
self.view.addSubview(textField)
You can check if all inputs are valid with this static function.
YMValidator.areValid(self)
To run the example project, clone the repo, and run pod install
from the Example directory first.
Drag and drop YMValidator.swift
into your project.
We are open to any proposals to improve this library!!
The best way to contribute is by submitting a pull request(Add comments in your code before to it). We’ll do our best to respond to your patch as soon as possible. You can also submit a new GitHub issue if you find bugs or have questions.
YMValidator is available under the MIT license. See the LICENSE file for more info.