YMValidator 0.2.1

YMValidator 0.2.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Ysee Monnier.



YMValidator

TextField Validation library for Swift (@IBDesignable & Programmatically)

Documentation

alt text

Usage

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,}"
}
With Storyboard
  1. Add your TextField
  2. Set the custom class YMValidator
  3. On attributs inspector, set Class Name and Error Message

CustomClass Inspector

  1. Set the error label to YMValidator
@IBOutlet weak var errorEmailLabel: UILabel!
@IBOutlet weak var inputEmail: YMValidator!

override func viewDidLoad() {
    super.viewDidLoad()
    self.errorEmailLabel.text = ""    
    self.inputEmail.setErrorLabel(self.errorEmailLabel)
}
Programmatically
//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)
Finally

You can check if all inputs are valid with this static function.

YMValidator.areValid(self)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Requirements
  • iOS 8.0+
  • Xcode 8 (Swift 3)
Manually

Drag and drop YMValidator.swift into your project.

Author

@YMonnier - [email protected]

Contributing

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. :octocat:

License

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