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()
}
}
}
Hide/Disable soft keyboard on Activity launch: Android
How do I check in SQLite whether a table exists?
Explain Fragment Life Cycle
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
What is Context?
How do I generate random numbers in Dart?
How can i comment inside xml file in android studio?
How to get a contact image using a phone number in android?
Check List for Generate Signed APK Android
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How To Set Text Color Programmatically Android TextView?
How to add jar/library files as a dependency in Android studio gradle file
What are the notifications available in android?
What is ANR in android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to copy database from assets folder in android using kotlin
How to Exit android app on back pressed?
Permission denied for window type 2010 in Marshmallow device
How to stop EditText focus at Activity startup in Android?
How to avoid multiple button click at same time in android?
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
What is the Different Between val and var in Kotlin?
Android FCM not receiving notifications when app is removed from background
How to Get bitmap from drawable: Android
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
How to extract date and time from Long type variable in Kotlin on Android "
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
Invoke-customs are only supported starting with android 0 --min-api 26
How to validate email address in Android with Kotlin?
How to Generate signed apk with android studio
How to get complete address from latitude and longitude?
What are Android Versions available?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What happens next when the device switches between portrait and landscape?
What is NetworkOnMainThread Exception?
How to find Android Device UDID or unique ID?
How to save activity State in Android?
How to reduce APK package size?