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 Exit android app on back pressed?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Fix Duplicate Files in APK Build.gradle Issue - RRutors
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to find Android Device UDID or unique ID?
Permission denied for window type 2010 in Marshmallow device
What is Application?
Fix Android Emulator Kill Error When Running Your App
How to get an image resource by it's name in android?
How to install/ uninstall apk by command line ADB
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Android Fragments?
Invoke-customs are only supported starting with android 0 --min-api 26
What is the difference between match_parent and fill_parent?
How to Use Deprecated Handler() in Android - RRutors Guide
How To Set Text Color Programmatically Android TextView?
What is ANR? How to avoid and resolve it?
Explain Fragment Life Cycle
How to Generate signed apk with android studio
How to avoid multiple button click at same time in android?
What are Android Versions available?
Key Points to remember while develop the Android Application.
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How do I check in SQLite whether a table exists?
How to reduce APK package size?
Open PDF in Google Drive with Intent in Android - RRutors
What are the notifications available in android?
How to convert milli seconds to hours, minutes and seconds in Android?
What is ANR in android?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to check Android version?
How to copy database from assets folder in android using kotlin
How to get screen size (width,height) in Android?
How to get complete address from latitude and longitude?
What is "shared preferences" in Android ?
What is the Different Between val and var in Kotlin?
How do i load image from drawable folder in Jetpack Compose?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Hide/Disable soft keyboard on Activity launch: Android
How to start a new activity on button click