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 convert milli seconds to hours, minutes and seconds in Android?
How to start a new activity on button click
How to get an image resource by it's name in android?
How to Generate signed apk with android studio
What is the difference between match_parent and fill_parent?
How to reduce APK package size?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to convert DP to Pixel and Pixel to Dp?
Set Activity to Fullscreen Mode in Android - RRutors
What are Android Versions available?
How can i comment inside xml file in android studio?
What is the Different Between val and var in Kotlin?
How to get complete address from latitude and longitude?
What is Context?
What is "shared preferences" in Android ?
Decompile APK Files: How to Get Source Code - RRutors Guide
Permission denied for window type 2010 in Marshmallow device
How do I generate random numbers in Dart?
Fix Android Emulator Kill Error When Running Your App
What is NetworkOnMainThread Exception?
Open PDF in Google Drive with Intent in Android - RRutors
Extract Date and Time from Long Type Variable - RRutors
How to Exit android app on back pressed?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Android Studio project R can't find
What is Android?
How to copy database from assets folder in android using kotlin
What are the notifications available in android?
What is ANR in android?
What is ANR? How to avoid and resolve it?
How to install/ uninstall apk by command line ADB
What happens next when the device switches between portrait and landscape?
How to validate email address in Android with Kotlin?
How To Set Text Color Programmatically Android TextView?
Hide/Disable soft keyboard on Activity launch: Android
Add Jar/Library Files as Dependency in Android Studio
How to Use Deprecated Handler() in Android - RRutors Guide
How to get screen size (width,height) in Android?
What is Intent? What is the difference between an implicit intent and an explicit intent?