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
What is Application?
Key Points to remember while develop the Android Application.
How To Set Text Color Programmatically Android TextView?
How to Exit android app on back pressed?
How to get a contact image using a phone number in android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
How to get an image resource by it's name in android?
Invoke-customs are only supported starting with android 0 --min-api 26
How do I generate random numbers in Dart?
What is "shared preferences" in Android ?
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
What is Android Fragments?
Check List for Generate Signed APK Android
How to stop EditText focus at Activity startup in Android?
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to install/ uninstall apk by command line ADB
How to convert DP to Pixel and Pixel to Dp?
What is Context?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
Explain Fragment Life Cycle
How to validate email address in Android with Kotlin?
How to start a new activity on button click
How to add jar/library files as a dependency in Android studio gradle file
How to copy database from assets folder in android using kotlin
Permission denied for window type 2010 in Marshmallow device
How do I check in SQLite whether a table exists?
How can i comment inside xml file in android studio?
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 do i load image from drawable folder in Jetpack Compose?
Android Studio project R can't find
How to find Android Device UDID or unique ID?
What is Android?
What is ANR in android?
What happens next when the device switches between portrait and landscape?
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What is the Different Between val and var in Kotlin?