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()
}
}
}
Explain Fragment Life Cycle
How do I check in SQLite whether a table exists?
Fix Android Emulator Kill Error When Running Your App
How to start a new activity on button click
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Extract Date and Time from Long Type Variable - RRutors
What are the notifications available in android?
What is NetworkOnMainThread Exception?
How to Exit android app on back pressed?
How do i load image from drawable folder in Jetpack Compose?
How to reduce APK package size?
How to get screen size (width,height) in Android?
What is the difference between match_parent and fill_parent?
How to Get bitmap from drawable: Android
What is "shared preferences" in Android ?
How to Generate signed apk with android studio
How to get a contact image using a phone number in android?
What is ANR in android?
What is Android?
What is Application?
How to install/ uninstall apk by command line ADB
How to avoid multiple button click at same time in android?
Invoke-customs are only supported starting with android 0 --min-api 26
How to stop EditText focus at Activity startup in Android?
What is Context?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Decompile APK Files: How to Get Source Code - RRutors Guide
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is ANR? How to avoid and resolve it?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to Use Deprecated Handler() in Android - RRutors Guide
How to validate email address in Android with Kotlin?
Add Jar/Library Files as Dependency in Android Studio
How do I generate random numbers in Dart?
How To Set Text Color Programmatically Android TextView?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Hide/Disable soft keyboard on Activity launch: Android
Check List for Generate Signed APK Android
How to convert DP to Pixel and Pixel to Dp?
What is the Different Between val and var in Kotlin?