CosmicMind/Material

How to set max characters limit for material textfield?

sachinrana028 opened this issue · 2 comments

How to set max characters limit for material textfield?

Hey! There is no specific way of setting a limit for Material's TextField. You can set limit using the UITextField way.

That said, you can allow user to type any number of characters but visually validate it via the validation api of ErrorTextField before using the content of that field. Check out for more info #1082

let usernameField = ErrorTextField()
usernameField.placeholder = "Username"
usernameField.detail = "You can use letters, numbers & periods"
usernameField.validator.autoValidationType = .always /// check for errors as user types
usernameField.validator
  .notEmpty(message: "Choose username")
  .max(length: 10, message: "A username can contain 10 characters at most")


/// later in somewhere
guard usernameField.isValid() else { return }

Thanks for the help @OrkhanAlikhanov.