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?
What is "shared preferences" in Android ?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to convert DP to Pixel and Pixel to Dp?
Open PDF in Google Drive with Intent in Android - RRutors
How to Generate signed apk with android studio
How to check Android version?
What is ANR in android?
What is the difference between match_parent and fill_parent?
Fix Play Store Rejection Due to SMS Permission - RRutors
How to install/ uninstall apk by command line ADB
How can i comment inside xml file in android studio?
How do I generate random numbers in Dart?
How do I check in SQLite whether a table exists?
FCM Not Receiving Notifications in Android - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Android Fragments?
How to Exit android app on back pressed?
How to get complete address from latitude and longitude?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to stop EditText focus at Activity startup in Android?
How to get a contact image using a phone number in android?
Permission denied for window type 2010 in Marshmallow device
Hide/Disable soft keyboard on Activity launch: Android
Add Jar/Library Files as Dependency in Android Studio
Check List for Generate Signed APK Android
How to start a new activity on button click
Set Activity to Fullscreen Mode in Android - RRutors
Android Studio project R can't find
Key Points to remember while develop the Android Application.
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How to Get bitmap from drawable: Android
How to find Android Device UDID or unique ID?
What is Context?
How to validate email address in Android with Kotlin?
How To Set Text Color Programmatically Android TextView?
How do i load image from drawable folder in Jetpack Compose?
Fix Android Emulator Kill Error When Running Your App
What is NetworkOnMainThread Exception?