Models | Examples |
---|---|
Display ads | Yahoo! |
Search ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The fmap function is only applied on Success values. | |
let success: Validation<String, Int> = Validation.Success(1) | |
success.fmap{ $0 + 1 } | |
// ==> Validation.Success(2) | |
let failure: Validation<String, Int> = Validation.Failure("error") | |
failure.fmap{$0 + 1} | |
// ==> Validation.Failure("error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Validate min length | |
func minLength(_ value:String, min:Int, fieldName:String) -> Validation<[String], String>{ | |
if(value.characters.count < min){ | |
return Validation.Failure(["\(fieldName) must have more than \(min) characters"]) | |
} else { | |
return Validation.Success(value) | |
} | |
} | |
//Validate match a regular expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Validate min length | |
func minLength(_ value:String, min:Int, fieldName:String) -> Validation<[String], String>{ | |
if(value.characters.count < min){ | |
return Validation.Failure(["\(fieldName) must have more than \(min) characters"]) | |
} else { | |
return Validation.Success(value) | |
} | |
} | |
//Validate match a regular expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func validatePassword(username: String, password:String) -> [String]{ | |
var errors:[String] = [] | |
if password.characters.count < 8 { | |
errors.append("Password must have more than 8 characters.") | |
} | |
if (password.range(of:"[\\W]", options: .regularExpression) == nil){ | |
errors.append("Password must contain a special character.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check if the password is long enough | |
func isPasswordLongEnough(_ password:String) -> Validation<[String], String> { | |
if password.characters.count < 8 { | |
return Validation.Failure(["Password must have more than 8 characters."]) | |
} else { | |
return Validation.Success(password) | |
} | |
} | |
NewerOlder