Email Address Validation in Android on EditText

Rahul Baradia picture Rahul Baradia · Oct 18, 2012 · Viewed 288.2k times · Source

How can we perform Email Validation on edittext in android ? I have gone through google & SO but I didn't find out a simple way to validate it.

Answer

user1737884 picture user1737884 · Apr 4, 2013

Java:

public static boolean isValidEmail(CharSequence target) {
    return (!TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches());
}

Kotlin:

fun CharSequence?.isValidEmail() = !isNullOrEmpty() && Patterns.EMAIL_ADDRESS.matcher(this).matches()

Edit: It will work On Android 2.2+ onwards !!

Edit: Added missing ;