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 the Different Between val and var in Kotlin?
What is ANR in android?
How to get complete address from latitude and longitude?
What are the notifications available in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Application?
Invoke-customs are only supported starting with android 0 --min-api 26
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is NetworkOnMainThread Exception?
Key Points to remember while develop the Android Application.
What is Context?
What is Intent? What is the difference between an implicit intent and an explicit intent?
FCM Not Receiving Notifications in Android - RRutors
Add Jar/Library Files as Dependency in Android Studio
How do i load image from drawable folder in Jetpack Compose?
How to avoid multiple button click at same time in android?
Extract Date and Time from Long Type Variable - RRutors
How to Exit android app on back pressed?
What is Android?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How do I generate random numbers in Dart?
Explain Fragment Life Cycle
How to convert milli seconds to hours, minutes and seconds in Android?
How To Set Text Color Programmatically Android TextView?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Open PDF in Google Drive with Intent in Android - RRutors
How do I check in SQLite whether a table exists?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to validate email address in Android with Kotlin?
How to get a contact image using a phone number in android?
How to get screen size (width,height) in Android?
What is the difference between match_parent and fill_parent?
Permission denied for window type 2010 in Marshmallow device
What are Android Versions available?
Check List for Generate Signed APK Android
Fix Play Store Rejection Due to SMS Permission - RRutors
How to Generate signed apk with android studio
What is ANR? How to avoid and resolve it?
How to install/ uninstall apk by command line ADB
How to stop EditText focus at Activity startup in Android?