user5370095
user5370095

Reputation:

How to count the number of characters in a text field iOS

I want to count the number of characters when User want to validate his password :

I came out so far with this code, but seems doesn't work

@IBOutlet var password: UITextField!

 if (Password!.count < 6)
        {
/// Not acceptable
        }

Upvotes: 4

Views: 10407

Answers (2)

R.AlAli
R.AlAli

Reputation: 85

for swift 5, I used this method and it is working fine

if password.text.count > 6 {
  //add scenario for this case here
}

Upvotes: 1

Kametrixom
Kametrixom

Reputation: 14973

How about

if password.text?.characters.count < 6 {
    ...
}

Upvotes: 14

Related Questions