How to implement a regex for password validation in Swift?

前端 未结 6 1457
刺人心
刺人心 2020-12-22 16:18

I want to implement a regex validaton for passwords in Swift? I have tried the following regex, but not successful

([(0-9)(A-Z)(!@#$%ˆ&*+-=<>)]+)([         


        
6条回答
  •  囚心锁ツ
    2020-12-22 16:55

    public func isValidPassword() -> Bool {
        let passwordRegex = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z!@#$%^&*()\\-_=+{}|?>.<,:;~`’]{8,}$"
        return NSPredicate(format: "SELF MATCHES %@", passwordRegex).evaluate(with: self)
    }
    

    If you need a quick fix. This is validation for a password with regex. Copy/paste in helper or extension file and use it.

提交回复
热议问题