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()
}
}
}
Check List for Generate Signed APK Android
Hide/Disable soft keyboard on Activity launch: Android
How to Get bitmap from drawable: Android
Set Activity to Fullscreen Mode in Android - RRutors
Invoke-customs are only supported starting with android 0 --min-api 26
How to copy database from assets folder in android using kotlin
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is NetworkOnMainThread Exception?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Context?
Permission denied for window type 2010 in Marshmallow device
How to get screen size (width,height) in Android?
What happens next when the device switches between portrait and landscape?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Add Jar/Library Files as Dependency in Android Studio
What is the difference between match_parent and fill_parent?
How to get an image resource by it's name in android?
How to Use Deprecated Handler() in Android - RRutors Guide
How to convert milli seconds to hours, minutes and seconds in Android?
How do i load image from drawable folder in Jetpack Compose?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to avoid multiple button click at same time in android?
What is ANR in android?
What is ANR? How to avoid and resolve it?
What is "shared preferences" in Android ?
What is Android?
How to start a new activity on button click
How to reduce APK package size?
Open PDF in Google Drive with Intent in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is Application?
How to Exit android app on back pressed?
Fix Android Emulator Kill Error When Running Your App
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get complete address from latitude and longitude?
What are the notifications available in android?
How To Set Text Color Programmatically Android TextView?
How to check Android version?
How to convert DP to Pixel and Pixel to Dp?