Function

maxLength

Returns InputTransformation that rejects input which causes the total length of the text field to be more than maxLength characters.

maxLength

Source set: Common
@Deprecated(
    message =
        "Use maxLengthTrim to truncate excess characters or maxLengthReject to reject input " +
            "exceeding maxLength.",
    replaceWith = ReplaceWith("this.maxLengthReject(maxLength)"),
)
public fun InputTransformation.maxLength(maxLength: Int): InputTransformation

Returns InputTransformation that rejects input which causes the total length of the text field to be more than maxLength characters.

This transformation also sets the maximum text length for accessibility services. When using an OutputTransformation that adds decorating characters, the announced maximum length may need to be adjusted to account for those characters. See the linked sample for an example of a custom maxLength filter that does this.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: