Merge branch 'master' of https://github.com/gberger/swift-validator into gberger-master

This commit is contained in:
Jeff Potter 2015-04-10 10:48:59 -06:00
commit 64eed84b72
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
//
// MaxLengthRule.swift
// Validator
//
// Created by Guilherme Berger on 4/6/15.
//
import Foundation
class MaxLengthRule: Rule {
private var DEFAULT_MAX_LENGTH: Int = 16
init(){}
init(length: Int){
self.DEFAULT_MAX_LENGTH = length
}
func validate(value: String) -> Bool {
return countElements(value) <= DEFAULT_MAX_LENGTH
}
func errorMessage() -> String {
return "Must be at most \(DEFAULT_MAX_LENGTH) characters long"
}
}