What\'s a good technique for validating an e-mail address (e.g. from a user input field) in Android? org.apache.commons.validator.routines.EmailValidator doesn\'t seem to be
Simplest Kotlin solution using extension functions:
fun String.isEmailValid() =
Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+"
).matcher(this).matches()
and then you can validate like this:
"testemail6589@gmail.com".isEmailValid()
If you are in kotlin-multiplatform without access to Pattern, this is the equivalent:
fun String.isValidEmail() = Regex(emailRegexStr).matches(this)