isEmailValid

Validates if this string is a properly formatted email address.

Uses Android's built-in Patterns.EMAIL_ADDRESS for validation, which checks for:

  • Proper email format (local-part@domain)

  • Valid characters in local and domain parts

  • At least one dot in the domain

Usage Examples

// In a ViewModel - validate user input
fun validateEmail(email: String): Boolean {
return email.isEmailValid()
}

// In a Composable - show error state
var email by remember { mutableStateOf("") }
var isError by remember { mutableStateOf(false) }

OutlinedTextField(
value = email,
onValueChange = {
email = it
isError = !it.isEmailValid()
},
isError = isError,
label = { Text("Email") }
)

// Null-safe usage
val userEmail: String? = getUserEmail()
if (userEmail.isEmailValid()) {
sendEmail(userEmail!!)
}

Valid Examples

  • "user@example.com" → true

  • "john.doe@company.co.uk" → true

  • "test+filter@gmail.com" → true

Invalid Examples

  • null → false

  • "" → false

  • "notanemail" → false

  • "@example.com" → false

  • "user@" → false

Receiver

String? The email string to validate (can be null).

Return

true if the string is a valid email address, false otherwise (including null/empty).

See also