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()
}
}
}
Hide/Disable soft keyboard on Activity launch: Android
What is Android?
How to stop EditText focus at Activity startup in Android?
How do I generate random numbers in Dart?
How To Set Text Color Programmatically Android TextView?
Check List for Generate Signed APK Android
How to get an image resource by it's name in android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to convert milli seconds to hours, minutes and seconds in Android?
What is Application?
How do i load image from drawable folder in Jetpack Compose?
How to reduce APK package size?
What are the notifications available in android?
What happens next when the device switches between portrait and landscape?
How to add jar/library files as a dependency in Android studio gradle file
How to install/ uninstall apk by command line ADB
What is Context?
What are Android Versions available?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
How to extract date and time from Long type variable in Kotlin on Android "
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
How to Exit android app on back pressed?
What are symmetric and asymmetric encryption in the way Android interacts with the server?
What is the Different Between val and var in Kotlin?
How to avoid multiple button click at same time in android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Permission denied for window type 2010 in Marshmallow device
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
What is Android Fragments?
How to convert DP to Pixel and Pixel to Dp?
How do I check in SQLite whether a table exists?
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
How to start a new activity on button click
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is ANR? How to avoid and resolve it?
What is NetworkOnMainThread Exception?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to get a contact image using a phone number in android?