I cannot convert this Java regular expression to swift:
^(?=.[a-z])(?=.[A-Z])(?=.*\d).{6,15}$
It basically checks for the input to have at least one uppercase, at least a number, and a minimum length of 6 characters and a maximum of 15.
The input to check against cames from a UITextField , and i have this function to check against:
func isValidPassword(candidate: String) -> Bool {
let passwordRegex = "(?=.[a-z])(?=.[A-Z])(?=.*\\d).{6,15}"
return NSPredicate(format: "SELF MATCHES %@", passwordRegex).evaluateWithObject(candidate)
}
Then, in my logic i do something like this:
if isValidPassword(textField.text) {
println("password is good")
} else {
println("password is wrong")
}
I am always getting that wrong password log.
I even tried modifying the expression with this Cheat Sheet with no luck.
Anyone can spot the flaw in the regular expression?
