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.
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 ;