iOS 17+
TextField("Password", text: $passwordText) .onChange(of: passwordText, { passwordText = String(passwordText.prefix(8)) })