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()
}
}
}
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Add Jar/Library Files as Dependency in Android Studio
Set Activity to Fullscreen Mode in Android - RRutors
How to convert milli seconds to hours, minutes and seconds in Android?
What happens next when the device switches between portrait and landscape?
How to install/ uninstall apk by command line ADB
How to start a new activity on button click
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Fix Android Emulator Kill Error When Running Your App
How to reduce APK package size?
How to check Android version?
Hide/Disable soft keyboard on Activity launch: Android
How to copy database from assets folder in android using kotlin
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is "shared preferences" in Android ?
Check List for Generate Signed APK Android
How to get an image resource by it's name in android?
What is Application?
What is Context?
Key Points to remember while develop the Android Application.
What are the notifications available in android?
How do I generate random numbers in Dart?
How to validate email address in Android with Kotlin?
How to stop EditText focus at Activity startup in Android?
Explain Fragment Life Cycle
What is NetworkOnMainThread Exception?
Fix Play Store Rejection Due to SMS Permission - RRutors
How to get a contact image using a phone number in android?
Extract Date and Time from Long Type Variable - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to save activity State in Android?
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get screen size (width,height) in Android?
How do I check in SQLite whether a table exists?
How to convert DP to Pixel and Pixel to Dp?
What is Android?
How to Generate signed apk with android studio
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to Get bitmap from drawable: Android