isValidFullName
Validates if this string represents a valid full name.
Validation Rules
Must contain at least two parts (first name and last name) separated by spaces
Each part must contain only letters (no numbers or special characters)
Null or empty strings are considered invalid
Note: This is a basic validation. Real-world names can include:
Hyphens (e.g., "Mary-Jane")
Apostrophes (e.g., "O'Brien")
Accented characters (e.g., "José", "Françoise")
Single names (mononyms)
Adjust validation logic based on your application's requirements and target audience.
Usage Examples
// In a signup form ViewModel
fun validateFullName(name: String): Boolean {
return name.isValidFullName()
}
// In a Composable
var fullName by remember { mutableStateOf("") }
val isValid = fullName.isValidFullName()
OutlinedTextField(
value = fullName,
onValueChange = { fullName = it },
isError = fullName.isNotEmpty() && !isValid,
label = { Text("Full Name") },
supportingText = {
if (fullName.isNotEmpty() && !isValid) {
Text("Enter first and last name")
}
}
)Valid Examples
"John Doe" → true
"Mary Jane Watson" → true (three parts is fine)
"Alice Smith Johnson" → true
Invalid Examples
null → false
"" → false
"John" → false (only one part)
"John123" → false (contains numbers)
"John-Doe" → false (contains hyphen - not a letter)
"John Doe!" → false (contains special character)
Receiver
String? The full name string to validate (can be null).
Return
true if the string represents a valid full name with at least first and last name, false otherwise.