I'm trying to handle error cases in my android app while signing up users. I want to make sure the email address provided is valid and by valid I mean the correct format : "[email protected]".
I have searched on google and stackoverflow, but couldn't find an exact answer in Kotlin.
Based on this answer in java (How should I validate an e-mail address?), you can use extension function to check the validity in kotlin.
fun String.isEmailValid(): Boolean {
return !TextUtils.isEmpty(this) && android.util.Patterns.EMAIL_ADDRESS.matcher(this).matches()
}
and then call
val str = ""
str.isEmailValid()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With