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()
}
}
}
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get a contact image using a phone number in android?
Extract Date and Time from Long Type Variable - RRutors
What are the notifications available in android?
How to find Android Device UDID or unique ID?
How to Get bitmap from drawable: Android
What is "shared preferences" in Android ?
How to reduce APK package size?
How to copy database from assets folder in android using kotlin
Permission denied for window type 2010 in Marshmallow device
FCM Not Receiving Notifications in Android - RRutors
How to stop EditText focus at Activity startup in Android?
How to convert milli seconds to hours, minutes and seconds in Android?
Fix Play Store Rejection Due to SMS Permission - RRutors
Add Jar/Library Files as Dependency in Android Studio
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Invoke-customs are only supported starting with android 0 --min-api 26
How to Exit android app on back pressed?
What is NetworkOnMainThread Exception?
How can i comment inside xml file in android studio?
How to Generate signed apk with android studio
What is ANR in android?
What is ANR? How to avoid and resolve it?
How do i load image from drawable folder in Jetpack Compose?
How to validate email address in Android with Kotlin?
How to get complete address from latitude and longitude?
Key Points to remember while develop the Android Application.
What are Android Versions available?
What is the difference between match_parent and fill_parent?
What is Application?
How to Use Deprecated Handler() in Android - RRutors Guide
How to start a new activity on button click
How do I check in SQLite whether a table exists?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is Android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to install/ uninstall apk by command line ADB
What is Context?
Explain Fragment Life Cycle