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()
}
}
}
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is the difference between match_parent and fill_parent?
What is Android?
How to validate email address in Android with Kotlin?
What is "shared preferences" in Android ?
How can i comment inside xml file in android studio?
Invoke-customs are only supported starting with android 0 --min-api 26
How to avoid multiple button click at same time in android?
How to Get bitmap from drawable: Android
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get an image resource by it's name in android?
How to find Android Device UDID or unique ID?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is NetworkOnMainThread Exception?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Fix Android Emulator Kill Error When Running Your App
What is the Different Between val and var in Kotlin?
How to get complete address from latitude and longitude?
Android Studio project R can't find
Extract Date and Time from Long Type Variable - RRutors
How do I check in SQLite whether a table exists?
How to stop EditText focus at Activity startup in Android?
How To Set Text Color Programmatically Android TextView?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Fix Play Store Rejection Due to SMS Permission - RRutors
What is Context?
What happens next when the device switches between portrait and landscape?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
FCM Not Receiving Notifications in Android - RRutors
What is ANR in android?
Key Points to remember while develop the Android Application.
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
How to Use Deprecated Handler() in Android - RRutors Guide
How to Exit android app on back pressed?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get screen size (width,height) in Android?
How to get a contact image using a phone number in android?
How to copy database from assets folder in android using kotlin
How to start a new activity on button click