Skip to main content

Overview

The input validation module provides Kotlin extension functions for validating user input, specifically email addresses and passwords. These validators are used throughout the authentication flow. File Location: com.demodogo.ev_sum_2.domain.validators.Validators

Email Validation

isBasicEmailValid()

Extension function that validates email format with basic checks.
fun String.isBasicEmailValid(): Boolean =
    contains("@") && contains(".") && emailDomain.isNotBlank()
this
String
required
The email string to validate
Returns: Boolean - true if the email meets basic validation criteria

Validation Rules

The email is considered valid if it:
  • Contains the ”@” symbol
  • Contains at least one ”.” character
  • Has a non-blank domain after the ”@” symbol

emailDomain Property

Helper property that extracts the domain portion of an email:
val String.emailDomain: String
    get() = substringAfter("@", missingDelimiterValue = "")
Returns an empty string if no ”@” symbol is found.

Usage Examples

// Valid emails
"[email protected]".isBasicEmailValid()  // true
"[email protected]".isBasicEmailValid()     // true
"[email protected]".isBasicEmailValid()  // true

// Invalid emails
"invalid".isBasicEmailValid()           // false (no @)
"no@domain".isBasicEmailValid()         // false (no .)
"@nodomain.com".isBasicEmailValid()     // false (blank domain)
"user@".isBasicEmailValid()             // false (blank domain)

Integration with UI

Used in authentication screens for email validation:
@Composable
fun LoginScreen() {
    var email by remember { mutableStateOf("") }
    
    Button(
        onClick = {
            val cleanEmail = email.trim()
            when {
                cleanEmail.isBlank() -> {
                    // Show error: "Completa tu email"
                }
                !cleanEmail.isBasicEmailValid() -> {
                    // Show error: "Email inválido"
                }
                else -> {
                    // Proceed with login
                }
            }
        }
    ) {
        Text("Login")
    }
}

Password Validation

isValidPassword()

Extension function that validates password strength requirements.
fun String.isValidPassword(): Boolean =
    length >= 6 && any { it.isLetter() } && any { it.isDigit() } && !contains(" ")
this
String
required
The password string to validate
Returns: Boolean - true if the password meets all strength requirements

Validation Rules

The password is considered valid if it:
  • Is at least 6 characters long
  • Contains at least one letter (a-z, A-Z)
  • Contains at least one digit (0-9)
  • Does not contain any spaces

Usage Examples

// Valid passwords
"pass123".isValidPassword()      // true
"Abc123".isValidPassword()       // true
"a1b2c3".isValidPassword()       // true

// Invalid passwords
"12345".isValidPassword()        // false (no letters)
"abcdef".isValidPassword()       // false (no digits)
"abc12".isValidPassword()        // false (too short)
"pass 123".isValidPassword()     // false (contains space)

Integration with UI

Used in registration screen for password validation:
@Composable
fun RegisterScreen() {
    var password by remember { mutableStateOf("") }
    
    Button(
        onClick = {
            when {
                password.isBlank() -> {
                    // Show error: "Completa tu contraseña"
                }
                !password.isValidPassword() -> {
                    // Show error: "La contraseña debe tener al menos 6 caracteres, 
                    //             1 letra y 1 número"
                }
                else -> {
                    // Proceed with registration
                }
            }
        }
    ) {
        Text("Register")
    }
}

Validation Messages

Common error messages used with these validators:
  • Blank email: “Completa tu email”
  • Invalid format: “Email inválido (ej: [email protected])”
  • Blank password: “Completa tu contraseña”
  • Invalid format: “La contraseña debe tener al menos 6 caracteres, 1 letra y 1 número”

Testing

These validators are designed to be easily testable since they’re pure functions:
@Test
fun testEmailValidation() {
    assertTrue("[email protected]".isBasicEmailValid())
    assertFalse("invalid".isBasicEmailValid())
    assertFalse("@nodomain".isBasicEmailValid())
}

@Test
fun testPasswordValidation() {
    assertTrue("pass123".isValidPassword())
    assertFalse("12345".isValidPassword())
    assertFalse("short1".isValidPassword())
    assertFalse("pass 123".isValidPassword())
}

Comparison with Speech Normalization

While speech normalization converts spoken words to typed format, input validation ensures the final result meets security and format requirements:
Converts spoken input to typed format:
normalizeEmailFromSpeech("admin arroba test punto cl")
// Returns: "[email protected]"

Source Code

View the complete implementation in the repository: app/src/main/java/com/demodogo/ev_sum_2/domain/validators/Validators.kt

Build docs developers (and LLMs) love