Merge branch 'gberger-master'
This commit is contained in:
commit
8a6c7f99cd
|
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 623F29931AD836E6005B26CB /* MaxLengthRule.swift */; };
|
||||
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637251AAA474B00BC8FCF /* MinLengthRule.swift */; };
|
||||
628637281AAA49E300BC8FCF /* ConfirmRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637271AAA49E300BC8FCF /* ConfirmRule.swift */; };
|
||||
62D1AE1D1A1E6D4400E4DFF8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D1AE1C1A1E6D4400E4DFF8 /* AppDelegate.swift */; };
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
623F29931AD836E6005B26CB /* MaxLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaxLengthRule.swift; sourceTree = "<group>"; };
|
||||
628637251AAA474B00BC8FCF /* MinLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MinLengthRule.swift; sourceTree = "<group>"; };
|
||||
628637271AAA49E300BC8FCF /* ConfirmRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfirmRule.swift; sourceTree = "<group>"; };
|
||||
62D1AE171A1E6D4400E4DFF8 /* Validator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Validator.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
|
|
@ -159,6 +161,7 @@
|
|||
62DC8D661AAA42700095DFA7 /* Rules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
623F29931AD836E6005B26CB /* MaxLengthRule.swift */,
|
||||
628637251AAA474B00BC8FCF /* MinLengthRule.swift */,
|
||||
62DC8D641AAA42520095DFA7 /* Rule.swift */,
|
||||
62DC8D691AAA42CE0095DFA7 /* EmailRule.swift */,
|
||||
|
|
@ -286,6 +289,7 @@
|
|||
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */,
|
||||
62DC8D711AAA43110095DFA7 /* ZipCodeRule.swift in Sources */,
|
||||
62D1AE521A1E6FF800E4DFF8 /* ValidationRule.swift in Sources */,
|
||||
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// MaxLengthRule.swift
|
||||
// Validator
|
||||
//
|
||||
// Created by Guilherme Berger on 4/6/15.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class MaxLengthRule: Rule {
|
||||
|
||||
private var DEFAULT_MAX_LENGTH: Int = 16
|
||||
|
||||
public init(){}
|
||||
|
||||
public init(length: Int){
|
||||
self.DEFAULT_MAX_LENGTH = length
|
||||
}
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
return countElements(value) <= DEFAULT_MAX_LENGTH
|
||||
}
|
||||
|
||||
public func errorMessage() -> String {
|
||||
return "Must be at most \(DEFAULT_MAX_LENGTH) characters long"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue