<commit_before>//
//  ViewController.swift
//  EGFormValidatorExample
//
//  Created by <NAME> on 30/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import EGFormValidator

class ViewController: ValidatorViewController {
    // Scrollview outlet
    @IBOutlet weak var scrollView: UIScrollView?
    
    
    // Inputs
    @IBOutlet weak var mandatoryTextField: UITextField!
    @IBOutlet weak var minLengthTextField: UITextField!
    @IBOutlet weak var emailTextField: UITextField!
    @IBOutlet weak var digitsOnlyTextField: UITextField!
    @IBOutlet weak var equaltyTextField_1: UITextField!
    @IBOutlet weak var equaltyTextField_2: UITextField!
    
    // Error labels
    @IBOutlet weak var mandatoryErrorLabel: UILabel!
    @IBOutlet weak var minLengthErrorLabel: UILabel!
    @IBOutlet weak var emailErrorLabel: UILabel!
    @IBOutlet weak var digitsOnlyErrorLabel: UILabel!
    @IBOutlet weak var equaltyErrorLabel: UILabel!
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        // Empty error labels (they have some text in the storyboard)
        self.mandatoryErrorLabel.text = ""
        self.minLengthErrorLabel.text = ""
        self.emailErrorLabel.text = ""
        self.digitsOnlyErrorLabel.text = ""
        self.equaltyErrorLabel.text = ""
        
        
        // add validators
        addValidators()
    }
    
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    
    
    
    
    //
    // Add validators
    func addValidators() {
        
        // Add mandatory validator
        self.addMandatoryValidation(control: self.mandatoryTextField,
                           errorPlaceholder: self.mandatoryErrorLabel,
                               errorMessage: "This field is required")
        
        
        
        // Add minlength validator
        self.addValidation(control: self.minLengthTextField,
                         minLength: 8,
                  errorPlaceholder: self.minLengthErrorLabel,
                      errorMessage: "Enter at least %d characters")
        
        
        
        // Email validator
        self.addEmailValidation(control: self.emailTextField,
                       errorPlaceholder: self.emailErrorLabel,
                           errorMessage: "Email is invalid")
        
        
        // Add digits only validator
        self.addDigitsOnlyValidation(control: self.digitsOnlyTextField,
                            errorPlaceholder: self.digitsOnlyErrorLabel,
                                errorMessage: "Some of the characters are not digits")
        
        
        
        // Equalty validator
        self.addValidation(control: self.equaltyTextField_1,
                           equalTo: self.equaltyTextField_2,
                           errorPlaceholder: self.equaltyErrorLabel,
                           errorMessage: "The strings don't match")
    }
    
    
    
    
    
    //
    // Perform validation
    @IBAction func validateButtonTapped(_ sender: Any) {
        
        if self.validate() {
            // show success alert
            let alert = UIAlertController(title: "Congratulations!",
                                          message: "All fields are valid",
                                          preferredStyle: .alert)
            
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.destructive, handler: nil))
            self.present(alert, animated: true, completion: nil)
            
            
        } else {
            // scroll to the first invalid input field
            self.scrollView?.scrollRectToVisible(self.firstFailedControl!.frame, animated: true)
        }
    }
}
<commit_msg>Add alphaNumericTextField example, code refactored<commit_after>//
//  ViewController.swift
//  EGFormValidatorExample
//
//  Created by <NAME> on 30/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import EGFormValidator

class ViewController: ValidatorViewController {
    // Scrollview outlet
    @IBOutlet weak var scrollView: UIScrollView?
    
    
    // Inputs
    @IBOutlet weak var mandatoryTextField: UITextField!
    @IBOutlet weak var minLengthTextField: UITextField!
    @IBOutlet weak var emailTextField: UITextField!
    @IBOutlet weak var digitsOnlyTextField: UITextField!
    @IBOutlet weak var equaltyTextField_1: UITextField!
    @IBOutlet weak var equaltyTextField_2: UITextField!
    @IBOutlet weak var alphaNumericTextField: UITextField!
    
    // Error labels
    @IBOutlet weak var mandatoryErrorLabel: UILabel!
    @IBOutlet weak var minLengthErrorLabel: UILabel!
    @IBOutlet weak var emailErrorLabel: UILabel!
    @IBOutlet weak var digitsOnlyErrorLabel: UILabel!
    @IBOutlet weak var equaltyErrorLabel: UILabel!
    @IBOutlet weak var aphaNumericErrorLabel: UILabel!
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        // Empty error labels (they have some text in the storyboard)
        self.mandatoryErrorLabel.text = ""
        self.minLengthErrorLabel.text = ""
        self.emailErrorLabel.text = ""
        self.digitsOnlyErrorLabel.text = ""
        self.equaltyErrorLabel.text = ""
        
        
        // add validators
        addValidators()
    }
    
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    
    
    
    
    //
    // Add validators
    func addValidators() {
        
        // Mandatory validator
        self.addValidatorMandatory(toControl: self.mandatoryTextField,
                            errorPlaceholder: self.mandatoryErrorLabel,
                                errorMessage: "This field is required")
        
        
        // Minlength validator
        self.addValidatorMinLength(toControl: self.minLengthTextField,
                            errorPlaceholder: self.minLengthErrorLabel,
                                errorMessage: "Enter at least %d characters",
                                   minLength: 8)
        
        // Email validator
        self.addValidatorEmail(toControl: self.emailTextField,
                        errorPlaceholder: self.emailErrorLabel,
                            errorMessage: "Email is invalid")
        
        
        // Digits only validator
        self.addValidatorDigitsOnly(toControl: self.digitsOnlyTextField,
                             errorPlaceholder: self.digitsOnlyErrorLabel,
                                 errorMessage: "Some of the characters are not digits")
        
        
        // Equalty validator
        self.addValidatorEqualTo(toControl: self.equaltyTextField_1,
                          errorPlaceholder: self.equaltyErrorLabel,
                              errorMessage: "The strings don't match",
                        compareWithControl: self.equaltyTextField_2)
        
        
        // Alphanumeric validator
        self.addValidatorAlphaNumeric(toControl: self.alphaNumericTextField,
                               errorPlaceholder: self.aphaNumericErrorLabel,
                                   errorMessage: "Only letters and digits are allowed")
    }
    
    
    
    
    
    //
    // Perform validation
    @IBAction func validateButtonTapped(_ sender: Any) {
        
        if self.validate() {
            // show success alert
            let alert = UIAlertController(title: "Congratulations!",
                                          message: "All fields are valid",
                                          preferredStyle: .alert)
            
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.destructive, handler: nil))
            self.present(alert, animated: true, completion: nil)
            
            
        } else {
            // scroll to the first invalid input field
            self.scrollView?.scrollRectToVisible(self.firstFailedControl!.frame, animated: true)
        }
    }
}

{'fraction_non_alphanumeric': 0.06897792706333973, 'fraction_numerical': 0.003598848368522073, 'mean_word_length': 1.737032173342088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6954744', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2080, 'n_words': 520}