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()
}
}
}
How to get screen size (width,height) in Android?
What are the notifications available in android?
How do I generate random numbers in Dart?
Hide/Disable soft keyboard on Activity launch: Android
How to avoid multiple button click at same time in android?
How do I check in SQLite whether a table exists?
How to install/ uninstall apk by command line ADB
What is Context?
What is NetworkOnMainThread Exception?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to find Android Device UDID or unique ID?
How do i load image from drawable folder in Jetpack Compose?
Extract Date and Time from Long Type Variable - RRutors
What is Android Fragments?
How to start a new activity on button click
Explain Fragment Life Cycle
What is Application?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Add Jar/Library Files as Dependency in Android Studio
Key Points to remember while develop the Android Application.
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is ANR? How to avoid and resolve it?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is the Different Between val and var in Kotlin?
Check List for Generate Signed APK Android
ERR_ACCESS_DENIED in Android Webview with sdk 30
What are Android Versions available?
How to reduce APK package size?
How to Generate signed apk with android studio
How to stop EditText focus at Activity startup in Android?
How to check Android version?
How to validate email address in Android with Kotlin?
Decompile APK Files: How to Get Source Code - RRutors Guide
How to copy database from assets folder in android using kotlin
What is the difference between match_parent and fill_parent?
What is Android?
What is ANR in android?