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()
}
}
}
What is NetworkOnMainThread Exception?
How to stop EditText focus at Activity startup in Android?
How to start a new activity on button click
Invoke-customs are only supported starting with android 0 --min-api 26
How can i comment inside xml file in android studio?
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
How to get screen size (width,height) in Android?
What are Android Versions available?
How to extract date and time from Long type variable in Kotlin on Android "
How do I generate random numbers in Dart?
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
How to Generate signed apk with android studio
What is Context?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How to reduce APK package size?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to get an image resource by it's name in android?
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What is Android Fragments?
What is "shared preferences" in Android ?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is the difference between match_parent and fill_parent?
How to save activity State in Android?
What is Application?
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
How to Exit android app on back pressed?
Android FCM not receiving notifications when app is removed from background
Explain Fragment Life Cycle
How to Get bitmap from drawable: Android
What happens next when the device switches between portrait and landscape?
What is ANR in android?
Permission denied for window type 2010 in Marshmallow device
What are symmetric and asymmetric encryption in the way Android interacts with the server?
Check List for Generate Signed APK Android
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
How to get a contact image using a phone number in android?
Android Studio project R can't find
How to find Android Device UDID or unique ID?
What is Android?