Latest 0.2.1
Homepage https://github.com/YMonnier/YMValidator
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform
Swift 3.0

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._%+-][email protected][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

``` Swift
//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)
Cocoapods

YMValidator is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "YMValidator"

If using Xcode 8, paste the following at the bottom of your Podfile, updating the Swift version if necessary:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '2.3' # or '3.0'
    end
  end
end
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.

Latest podspec

{
    "name": "YMValidator",
    "version": "0.2.1",
    "summary": "TextField Validation library for Swift (@IBDesignable & Programmatically)",
    "description": "TextField Validation library for Swift using IBDesignable from Storyboard or Programmatically.",
    "homepage": "https://github.com/YMonnier/YMValidator",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ysee Monnier": "[email protected]"
    },
    "source": {
        "git": "https://github.com/YMonnier/YMValidator.git",
        "tag": "0.2.1"
    },
    "social_media_url": "https://twitter.com/Ysee88",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "YMValidator/Classes/**/*"
}

Pin It on Pinterest

Share This