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()
}
}
}
Invoke-customs are only supported starting with android 0 --min-api 26
What is "shared preferences" in Android ?
What is the difference between match_parent and fill_parent?
How to Get bitmap from drawable: Android
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?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to get an image resource by it's name in android?
How to check Android version?
How can i comment inside xml file in android studio?
How to Generate signed apk with android studio
Check List for Generate Signed APK Android
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to convert DP to Pixel and Pixel to Dp?
Set Activity to Fullscreen Mode in Android - RRutors
Android Studio project R can't find
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Application?
How to get complete address from latitude and longitude?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is Context?
What is NetworkOnMainThread Exception?
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
Open PDF in Google Drive with Intent in Android - RRutors
How do i load image from drawable folder in Jetpack Compose?
How to get a contact image using a phone number in android?
How to convert milli seconds to hours, minutes and seconds in Android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to copy database from assets folder in android using kotlin
Add Jar/Library Files as Dependency in Android Studio
How to Exit android app on back pressed?
FCM Not Receiving Notifications in Android - RRutors
What is the Different Between val and var in Kotlin?
Key Points to remember while develop the Android Application.
How to find Android Device UDID or unique ID?
Permission denied for window type 2010 in Marshmallow device
Explain Fragment Life Cycle
How to validate email address in Android with Kotlin?
What are Android Versions available?