Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active August 29, 2015 14:10
Show Gist options
  • Save jpotts18/aaa5ed98d0789ec75899 to your computer and use it in GitHub Desktop.
Save jpotts18/aaa5ed98d0789ec75899 to your computer and use it in GitHub Desktop.
class SunilValidation : Validation {
// 8 characters. one uppercase, one lowercase, one number
var SUNIL_REGEX = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).{8,}$"
// No length. one uppercase, one lowercase, one number
var NO_LENGTH_SUNIL_REGEX = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*$"
func validate(value: String) -> (Bool, ValidationErrorType) {
if let sunilTest = NSPredicate(format: "SELF MATCHES %@", SUNIL_REGEX) {
if sunilTest.evaluateWithObject(value) {
return (true, .NoError)
}
return (false, .Password) // You will need to add a ValidationRuleType and ValidationErrorType
}
return (false, .Password)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment