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()
}
}
}
FCM Not Receiving Notifications in Android - RRutors
Fix Android Emulator Kill Error When Running Your App
Open PDF in Google Drive with Intent in Android - RRutors
How to reduce APK package size?
What is Application?
What is Context?
How to convert DP to Pixel and Pixel to Dp?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to check Android version?
Hide/Disable soft keyboard on Activity launch: Android
What is Android Fragments?
How to get a contact image using a phone number in android?
What is the difference between match_parent and fill_parent?
Extract Date and Time from Long Type Variable - RRutors
ERR_ACCESS_DENIED in Android Webview with sdk 30
How can i comment inside xml file in android studio?
What are Android Versions available?
How to start a new activity on button click
What is ANR in android?
How do I check in SQLite whether a table exists?
Android Studio project R can't find
What happens next when the device switches between portrait and landscape?
What is NetworkOnMainThread Exception?
What are the notifications available in android?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
How to find Android Device UDID or unique ID?
How to get an image resource by it's name in android?
Fix Play Store Rejection Due to SMS Permission - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is ANR? How to avoid and resolve it?
What is Android?
Invoke-customs are only supported starting with android 0 --min-api 26
How to Get bitmap from drawable: Android
What is the Different Between val and var in Kotlin?
Permission denied for window type 2010 in Marshmallow device
Add Jar/Library Files as Dependency in Android Studio
How to get screen size (width,height) in Android?
Explain Fragment Life Cycle
How to get complete address from latitude and longitude?