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 can i comment inside xml file in android studio?
What is Application?
How to save activity State in Android?
Android Studio project R can't find
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is the Different Between val and var in Kotlin?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Hide/Disable soft keyboard on Activity launch: Android
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is "shared preferences" in Android ?
How to Use Deprecated Handler() in Android - RRutors Guide
How to convert milli seconds to hours, minutes and seconds in Android?
How to reduce APK package size?
Set Activity to Fullscreen Mode in Android - RRutors
How to validate email address in Android with Kotlin?
How to Generate signed apk with android studio
How to check Android version?
FCM Not Receiving Notifications in Android - RRutors
How do I check in SQLite whether a table exists?
What is NetworkOnMainThread Exception?
How to get screen size (width,height) in Android?
What happens next when the device switches between portrait and landscape?
How to get a contact image using a phone number in android?
How To Set Text Color Programmatically Android TextView?
How to install/ uninstall apk by command line ADB
Fix Play Store Rejection Due to SMS Permission - RRutors
Extract Date and Time from Long Type Variable - RRutors
Explain Fragment Life Cycle
Key Points to remember while develop the Android Application.
How to get an image resource by it's name in android?
How do i load image from drawable folder in Jetpack Compose?
Check List for Generate Signed APK Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Android?
What is ANR in android?
Add Jar/Library Files as Dependency in Android Studio
How to get complete address from latitude and longitude?
How to start a new activity on button click
How to copy database from assets folder in android using kotlin
Symmetric vs Asymmetric Encryption in Android Server - RRutors