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()
}
}
}
FCM Not Receiving Notifications in Android - RRutors
What is the Different Between val and var in Kotlin?
What is ANR? How to avoid and resolve it?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to validate email address in Android with Kotlin?
Key Points to remember while develop the Android Application.
How to start a new activity on button click
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get complete address from latitude and longitude?
How to stop EditText focus at Activity startup in Android?
How To Set Text Color Programmatically Android TextView?
What is Context?
How to copy database from assets folder in android using kotlin
Invoke-customs are only supported starting with android 0 --min-api 26
How to convert DP to Pixel and Pixel to Dp?
How to save activity State in Android?
Fix Play Store Rejection Due to SMS Permission - RRutors
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Open PDF in Google Drive with Intent in Android - RRutors
Add Jar/Library Files as Dependency in Android Studio
How to check Android version?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is "shared preferences" in Android ?
What is the difference between match_parent and fill_parent?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Permission denied for window type 2010 in Marshmallow device
How to install/ uninstall apk by command line ADB
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is NetworkOnMainThread Exception?
How to find Android Device UDID or unique ID?
What happens next when the device switches between portrait and landscape?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
How to reduce APK package size?
How do i load image from drawable folder in Jetpack Compose?
What are the notifications available in android?
How to Get bitmap from drawable: Android
Fix Android Emulator Kill Error When Running Your App
How do I check in SQLite whether a table exists?
What is Intent? What is the difference between an implicit intent and an explicit intent?