Merge remote-tracking branch 'upstream/master'

This commit is contained in:
mla2c 2015-06-12 08:36:10 +02:00
commit d3b92f5a5f
6 changed files with 30 additions and 23 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -53,7 +53,8 @@ override func viewDidLoad() {
validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()])
// You can pass in error labels with your rules
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()])
// You can pass in custom error messages to regex rules (such as ZipCodeRule and EmailRule)
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule(message: "Invalid email")])
// You can validate against other fields using ConfirmRule
validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)])
@ -101,31 +102,16 @@ func validationFailed(errors:[UITextField:ValidationError]) {
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 implements the Rule protocol
Create a class that inherits from RegexRule
```swift
class SSNVRule: Rule {
let REGEX = "^\\d{3}-\\d{2}-\\d{4}$"
init(){}
// allow for custom variables to be passed
init(regex:String){
self.REGEX = regex
}
func validate(value: String) -> Bool {
if let ssnTest = NSPredicate(format: "SELF MATCHES %@", REGEX) {
if ssnTest.evaluateWithObject(value) {
return true
}
return false
}
}
func errorMessage() -> String{
return "Not a valid SSN"
class SSNVRule: RegexRule {
static let regex = "^\\d{3}-\\d{2}-\\d{4}$"
convenience init(message : String = "Not a valid SSN"){
self.init(regex: SSNVRule.regex, message : message)
}
}
```

View File

@ -9,6 +9,7 @@
import Foundation
public class EmailRule: RegexRule {
static let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"

View File

@ -17,10 +17,18 @@ public class PasswordRule : RegexRule {
//
// no length. One uppercase. One lowercae. One number.
// static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*?$"
<<<<<<< HEAD
static let regex = "^(?=.*?[A-Z]).{8,}$"
public convenience init(message : String = "Must be 8 characters with 1 uppercase") {
self.init(regex: PasswordRule.regex, message : message)
=======
static let regex = "^(?=.*?[A-Z]).{8,}$"
public convenience init(message : String = "Must be 8 characters with 1 uppercase") {
self.init(regex: PasswordRule.regex, message : message)
>>>>>>> upstream/master
}
}

View File

@ -12,10 +12,17 @@ public class RegexRule : Rule {
private var REGEX: String = "^(?=.*?[A-Z]).{8,}$"
private var message : String
<<<<<<< HEAD
public init(regex: String, message: String = "Invalid Regular Expression"){
self.REGEX = regex
self.message = message
=======
public init(regex: String, message: String = "Invalid Regular Expression"){
self.REGEX = regex
self.message = message
>>>>>>> upstream/master
}
public func validate(value: String) -> Bool {

View File

@ -10,7 +10,12 @@ import Foundation
public class ZipCodeRule: RegexRule {
<<<<<<< HEAD
public convenience init(message : String = "Enter a valid 5 digit zipcode"){
self.init(regex: "\\d{5}", message : message)
=======
public convenience init(message : String = "Enter a valid 5 digit zipcode"){
self.init(regex: "\\d{5}", message : message)
>>>>>>> upstream/master
}
}