With the below code we can validate email address in android.
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
private lateinit var editText: EditText
private lateinit var email: String
private val emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "KotlinApp"
editText = findViewById(R.id.editText)
email = editText.text.toString().trim()
}
fun validateEmail(view: View?) {
if (email.matches(emailPattern.toRegex())) {
Toast.makeText(applicationContext, "Valid email address",
Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(applicationContext, "Invalid email address",
Toast.LENGTH_SHORT).show()
}
}
}
What is Context?
What are the notifications available in android?
How to convert milli seconds to hours, minutes and seconds in Android?
What are Android Versions available?
Extract Date and Time from Long Type Variable - RRutors
How to reduce APK package size?
How to convert DP to Pixel and Pixel to Dp?
What is the difference between match_parent and fill_parent?
How to Use Deprecated Handler() in Android - RRutors Guide
What is Android Fragments?
How do I generate random numbers in Dart?
Fix Android Emulator Kill Error When Running Your App
How to Exit android app on back pressed?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How to find Android Device UDID or unique ID?
What is ANR? How to avoid and resolve it?
Android Studio project R can't find
Add Jar/Library Files as Dependency in Android Studio
How to check Android version?
How To Set Text Color Programmatically Android TextView?
Open PDF in Google Drive with Intent in Android - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get screen size (width,height) in Android?
Set Activity to Fullscreen Mode in Android - RRutors
How to validate email address in Android with Kotlin?
How to Get bitmap from drawable: Android
How to get complete address from latitude and longitude?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How can i comment inside xml file in android studio?
What is the Different Between val and var in Kotlin?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Check List for Generate Signed APK Android
How to install/ uninstall apk by command line ADB
ERR_ACCESS_DENIED in Android Webview with sdk 30
Explain Fragment Life Cycle
Key Points to remember while develop the Android Application.
What is "shared preferences" in Android ?
Invoke-customs are only supported starting with android 0 --min-api 26