I want to implement a regex validaton for passwords in Swift? I have tried the following regex, but not successful
([(0-9)(A-Z)(!@#$%ˆ&*+-=<>)]+)([
func validpassword(mypassword : String) -> Bool
{
let passwordreg = ("(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z])(?=.*[@#$%^&*]).{8,}")
let passwordtesting = NSPredicate(format: "SELF MATCHES %@", passwordreg)
return passwordtesting.evaluate(with: mypassword)
}
@IBOutlet weak var password_textfield: UITextField! //create a Password text field IBOutlet
@IBAction func login_btton(_ sender: UIButton) { //Click & Call to Login Button
let password = validpassword(mypassword: password_textfield.text!) //get text Field data & checked through the function
if(password == false)
{
print("Valid Password") //Use to Alert Msg Box
}
else
{
print("Login Safe") //Use to Alert Msg Box
}
}
## Function Use to validation is password and confirm password is same, Password must have more then some characters , Password contain some special character , Password must one digit , Password must one uppercase letter ##