Changes from leodasvacas fork (Custom messages for regex rules, commit 157e9791fb)
This commit is contained in:
parent
5a3ddcb795
commit
ba9615cc85
|
|
@ -10,15 +10,9 @@ import Foundation
|
|||
|
||||
public class EmailRule: RegexRule {
|
||||
|
||||
public init(){
|
||||
super.init(regex: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}")
|
||||
}
|
||||
static let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
|
||||
|
||||
override public init(regex:String){
|
||||
super.init(regex: regex)
|
||||
}
|
||||
|
||||
override public func errorMessage() -> String {
|
||||
return "Must be a valid email address"
|
||||
public convenience init(message : String = "Must be a valid email address"){
|
||||
self.init(regex: EmailRule.regex, message: message)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,21 +13,14 @@ public class PasswordRule : RegexRule {
|
|||
// Alternative Regexes
|
||||
|
||||
// 8 characters. One uppercase. One Lowercase. One number.
|
||||
// var PASSWORD_REGEX = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).{8,}$"
|
||||
// static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).{8,}$"
|
||||
//
|
||||
// no length. One uppercase. One lowercae. One number.
|
||||
// var PASSWORD_REGEX = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*?$"
|
||||
// static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*?$"
|
||||
|
||||
public init(){
|
||||
super.init(regex: "^(?=.*?[A-Z]).{8,}$")
|
||||
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)
|
||||
}
|
||||
|
||||
override public init(regex: String) {
|
||||
super.init(regex: regex)
|
||||
}
|
||||
|
||||
override public func errorMessage() -> String {
|
||||
return "Must be 8 characters with 1 uppercase"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,9 +11,11 @@ import Foundation
|
|||
public class RegexRule : Rule {
|
||||
|
||||
private var REGEX: String = "^(?=.*?[A-Z]).{8,}$"
|
||||
private var message : String
|
||||
|
||||
public init(regex: String){
|
||||
public init(regex: String, message: String = "Invalid Regular Expression"){
|
||||
self.REGEX = regex
|
||||
self.message = message
|
||||
}
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
|
|
@ -22,6 +24,6 @@ public class RegexRule : Rule {
|
|||
}
|
||||
|
||||
public func errorMessage() -> String {
|
||||
return "Invalid Regular Expression"
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,16 +10,7 @@ import Foundation
|
|||
|
||||
public class ZipCodeRule: RegexRule {
|
||||
|
||||
public init(){
|
||||
super.init(regex: "\\d{5}")
|
||||
public convenience init(message : String = "Enter a valid 5 digit zipcode"){
|
||||
self.init(regex: "\\d{5}", message : message)
|
||||
}
|
||||
|
||||
override public init(regex: String) {
|
||||
super.init(regex: regex)
|
||||
}
|
||||
|
||||
public override func errorMessage() -> String {
|
||||
return "Enter a valid 5 digit zipcode"
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue