3

I want to use the UITextInputPasswordRules in my SwiftUI Code for validating a password from the user.

The Swift code would look like this Codesnippet:

let newPasswordTextField = UITextField()
newPasswordTextField.passwordRules = UITextInputPasswordRules(descriptor: "required: lower; required: upper; required: digit; required: special; allowed: unicode; minlength: 10;")

My SwiftUI Code looks like that, so far:

struct CustomPasswordTextField: View {
    let passwordRuleDescription: String = "required: lower; required: upper; required: digit; required: special; allowed: unicode; minlength: 10;"
    var placeholder: Text
    @Binding var text: String

    var body: some View {
        ZStack(alignment: .leading) {
            if text.isEmpty { placeholder }
            SecureField("", text: $text)
        }
    }
}

How can I apply the passwordRuleDescription to the SecureField(", text: $text")?

Jonas Deichelmann
  • 2,568
  • 1
  • 21
  • 33

0 Answers0