0Pricing
Android Academy · Lesson

Validating Input

Check input and show helpful errors.

Why Validate Input

Users make mistakes: an empty name, a malformed email, a too-short password. Good forms catch these early and explain clearly what to fix.

In this lesson you'll add validation to Compose forms, show inline errors, and disable the submit button until everything is valid.

A Validation Rule is Just a Function

Keep validation logic as plain Kotlin functions that take a value and return whether it's valid (or an error message). This makes rules reusable and easy to test.

Here is a simple email check.

fun emailError(email: String): String? = when {
    email.isBlank() -> "Email is required"
    !email.contains("@") -> "Enter a valid email"
    else -> null
}

All lessons in this course

  1. TextField and User Input
  2. Managing Form State
  3. Validating Input
  4. Keyboard Options and Actions
← Back to Android Academy