commit
c5a6bcbe3a
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "Swift-Validator"
|
||||
s.version = "2.0.2"
|
||||
s.name = "Swift_Validator"
|
||||
s.version = "2.0.5"
|
||||
s.summary = "A UITextField Validation library for Swift"
|
||||
s.homepage = "https://github.com/jpotts18/swift-validator"
|
||||
s.screenshots = "https://raw.githubusercontent.com/jpotts18/swift-validator/master/swift-validator-v2.gif"
|
||||
|
|
@ -8,7 +8,9 @@ Pod::Spec.new do |s|
|
|||
s.author = { "Jeff" => "jeff.potter6@gmail.com" }
|
||||
s.social_media_url = "http://twitter.com/jpotts18"
|
||||
s.platform = :ios
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.source = { :git => "https://github.com/jpotts18/swift-validator.git", :tag => "2.0.2" }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.source = { :git => "https://github.com/asotog/swift-validator.git", :tag => "2.0.5" }
|
||||
s.source_files = "Validator/*.swift"
|
||||
s.frameworks = ['Foundation', 'UIKit']
|
||||
s.requires_arc = true
|
||||
end
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class ConfirmationRule: Rule {
|
||||
public class ConfirmationRule: Rule {
|
||||
|
||||
let confirmField: UITextField
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class ConfirmationRule: Rule {
|
|||
self.confirmField = confirmField
|
||||
}
|
||||
|
||||
func validate(value: String) -> Bool {
|
||||
public func validate(value: String) -> Bool {
|
||||
if self.confirmField.text == value {
|
||||
return true
|
||||
} else {
|
||||
|
|
@ -25,7 +25,7 @@ class ConfirmationRule: Rule {
|
|||
}
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return "This field does not match"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,23 +8,27 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
class EmailRule: Rule {
|
||||
public class EmailRule: Rule {
|
||||
|
||||
private let REGEX: String
|
||||
|
||||
init(){
|
||||
public init(){
|
||||
self.REGEX = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
|
||||
}
|
||||
|
||||
init(regex:String){
|
||||
public init(regex:String){
|
||||
REGEX = regex
|
||||
}
|
||||
|
||||
func validate(value: String) -> Bool {
|
||||
return NSPredicate(format: "SELF MATCHES %@", self.REGEX).evaluateWithObject(value)
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) {
|
||||
if test.evaluateWithObject(value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return "Must be a valid email address"
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,13 @@
|
|||
import Foundation
|
||||
|
||||
|
||||
class FullNameRule : Rule {
|
||||
public class FullNameRule : Rule {
|
||||
|
||||
var message:String {
|
||||
return "Please provide a first & last name"
|
||||
}
|
||||
|
||||
func validate(value:String) -> Bool {
|
||||
public func validate(value:String) -> Bool {
|
||||
|
||||
var nameArray:[String] = split(value) { $0 == " " }
|
||||
if nameArray.count >= 2 {
|
||||
|
|
@ -23,8 +23,7 @@ class FullNameRule : Rule {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
class PasswordRule : Rule {
|
||||
public class PasswordRule : Rule {
|
||||
|
||||
// Alternative Regexes
|
||||
|
||||
|
|
@ -22,19 +22,24 @@ class PasswordRule : Rule {
|
|||
|
||||
private let REGEX: String
|
||||
|
||||
init(){
|
||||
public init(){
|
||||
self.REGEX = "^(?=.*?[A-Z]).{8,}$"
|
||||
}
|
||||
|
||||
init(regex:String){
|
||||
public init(regex:String){
|
||||
self.REGEX = regex
|
||||
}
|
||||
|
||||
func validate(value: String) -> Bool {
|
||||
return NSPredicate(format: "SELF MATCHES %@", self.REGEX).evaluateWithObject(value)
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) {
|
||||
if test.evaluateWithObject(value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return "Must be 8 characters with 1 uppercase"
|
||||
}
|
||||
}
|
||||
|
|
@ -9,22 +9,22 @@
|
|||
import Foundation
|
||||
|
||||
|
||||
class RequiredRule: Rule {
|
||||
public class RequiredRule: Rule {
|
||||
|
||||
init(){}
|
||||
public init(){}
|
||||
|
||||
var message: String {
|
||||
return "This field is required"
|
||||
}
|
||||
|
||||
func validate(value:String) -> Bool {
|
||||
public func validate(value:String) -> Bool {
|
||||
if value.isEmpty {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
protocol Rule {
|
||||
public protocol Rule {
|
||||
func validate(value:String) -> Bool
|
||||
func errorMessage() -> String
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class ValidationError {
|
||||
let textField:UITextField
|
||||
var errorLabel:UILabel?
|
||||
let errorMessage:String
|
||||
public class ValidationError {
|
||||
public let textField:UITextField
|
||||
public var errorLabel:UILabel?
|
||||
public let errorMessage:String
|
||||
|
||||
init(textField:UITextField, error:String){
|
||||
public init(textField:UITextField, error:String){
|
||||
self.textField = textField
|
||||
self.errorMessage = error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class ValidationRule {
|
||||
var textField:UITextField
|
||||
var errorLabel:UILabel?
|
||||
var rules:[Rule] = []
|
||||
public class ValidationRule {
|
||||
public var textField:UITextField
|
||||
public var errorLabel:UILabel?
|
||||
public var rules:[Rule] = []
|
||||
|
||||
init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){
|
||||
public init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){
|
||||
self.textField = textField
|
||||
self.errorLabel = errorLabel
|
||||
self.rules = rules
|
||||
}
|
||||
|
||||
func validateField() -> ValidationError? {
|
||||
public func validateField() -> ValidationError? {
|
||||
for rule in rules {
|
||||
var isValid:Bool = rule.validate(textField.text)
|
||||
if !isValid {
|
||||
|
|
|
|||
|
|
@ -9,29 +9,29 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
@objc protocol ValidationDelegate {
|
||||
@objc public protocol ValidationDelegate {
|
||||
func validationWasSuccessful()
|
||||
func validationFailed(errors:[UITextField:ValidationError])
|
||||
}
|
||||
|
||||
class Validator {
|
||||
public class Validator {
|
||||
// dictionary to handle complex view hierarchies like dynamic tableview cells
|
||||
var errors:[UITextField:ValidationError] = [:]
|
||||
var validations:[UITextField:ValidationRule] = [:]
|
||||
public var errors:[UITextField:ValidationError] = [:]
|
||||
public var validations:[UITextField:ValidationRule] = [:]
|
||||
|
||||
init(){}
|
||||
public init(){}
|
||||
|
||||
// MARK: Using Keys
|
||||
|
||||
func registerField(textField:UITextField, rules:[Rule]) {
|
||||
public func registerField(textField:UITextField, rules:[Rule]) {
|
||||
validations[textField] = ValidationRule(textField: textField, rules: rules, errorLabel: nil)
|
||||
}
|
||||
|
||||
func registerField(textField:UITextField, errorLabel:UILabel, rules:[Rule]) {
|
||||
public func registerField(textField:UITextField, errorLabel:UILabel, rules:[Rule]) {
|
||||
validations[textField] = ValidationRule(textField: textField, rules:rules, errorLabel:errorLabel)
|
||||
}
|
||||
|
||||
func validateAll(delegate:ValidationDelegate) {
|
||||
public func validateAll(delegate:ValidationDelegate) {
|
||||
|
||||
for field in validations.keys {
|
||||
if let currentRule:ValidationRule = validations[field] {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
class ZipCodeRule: Rule {
|
||||
|
||||
public class ZipCodeRule: Rule {
|
||||
|
||||
private let REGEX: String
|
||||
|
||||
init(){
|
||||
|
|
@ -18,12 +18,17 @@ class ZipCodeRule: Rule {
|
|||
init(regex:String){
|
||||
self.REGEX = regex
|
||||
}
|
||||
|
||||
func validate(value: String) -> Bool {
|
||||
return NSPredicate(format: "SELF MATCHES %@", self.REGEX).evaluateWithObject(value)
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) {
|
||||
if test.evaluateWithObject(value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func errorMessage() -> String {
|
||||
public func errorMessage() -> String {
|
||||
return "Enter a valid 5 digit zipcode"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue