Validation Result
The result of a KotIndia validator call.
Every validator in io.github.kotindia returns a ValidationResult. Use Valid to check success and Invalid to retrieve the failure reason.
Callers should use a sealed when expression to branch on the result:
val result = Mobile.validate("9876543210")
when (result) {
is ValidationResult.Valid -> println("Valid input")
is ValidationResult.Invalid -> println("Invalid: ${result.reason}")
}Content copied to clipboard
Or use the convenience isValid shorthand (available on each validator object):
val ok: Boolean = Mobile.validate("9876543210") is ValidationResult.ValidContent copied to clipboard
Validators in this library never throw. All error paths are represented as Invalid with an appropriate InvalidReason.
Samples
val result = Aadhaar.validate("234567890124")
when (result) {
is ValidationResult.Valid -> println("Valid")
is ValidationResult.Invalid -> println("Invalid: ${result.reason}")
}Content copied to clipboard