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 are the notifications available in android?
What is the difference between match_parent and fill_parent?
What is Android Fragments?
Fix Play Store Rejection Due to SMS Permission - RRutors
How to get a contact image using a phone number in android?
How to get complete address from latitude and longitude?
How to save activity State in Android?
Add Jar/Library Files as Dependency in Android Studio
How to avoid multiple button click at same time in android?
What is Android?
Key Points to remember while develop the Android Application.
Set Activity to Fullscreen Mode in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to find Android Device UDID or unique ID?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to validate email address in Android with Kotlin?
How to get an image resource by it's name in android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Application?
Permission denied for window type 2010 in Marshmallow device
How to check Android version?
How to reduce APK package size?
Open PDF in Google Drive with Intent in Android - RRutors
Fix Android Emulator Kill Error When Running Your App
What are Android Versions available?
What is Context?
What is ANR in android?
How to Exit android app on back pressed?
How to copy database from assets folder in android using kotlin
How To Set Text Color Programmatically Android TextView?
What is the Different Between val and var in Kotlin?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to convert milli seconds to hours, minutes and seconds in Android?
How to stop EditText focus at Activity startup in Android?
Hide/Disable soft keyboard on Activity launch: Android
How can i comment inside xml file in android studio?
How to get screen size (width,height) in Android?
How do i load image from drawable folder in Jetpack Compose?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is "shared preferences" in Android ?