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 to save activity State in Android?
Permission denied for window type 2010 in Marshmallow device
What is ANR in android?
What is Android Fragments?
Open PDF in Google Drive with Intent in Android - RRutors
What is ANR? How to avoid and resolve it?
What are Android Versions available?
How can i comment inside xml file in android studio?
Key Points to remember while develop the Android Application.
How to Get bitmap from drawable: Android
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Hide/Disable soft keyboard on Activity launch: Android
How to reduce APK package size?
How to install/ uninstall apk by command line ADB
How to Use Deprecated Handler() in Android - RRutors Guide
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to stop EditText focus at Activity startup in Android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is Intent? What is the difference between an implicit intent and an explicit intent?
How do I generate random numbers in Dart?
Fix Play Store Rejection Due to SMS Permission - RRutors
How to convert DP to Pixel and Pixel to Dp?
Fix Android Emulator Kill Error When Running Your App
Check List for Generate Signed APK Android
Android Studio project R can't find
How to Exit android app on back pressed?
How to find Android Device UDID or unique ID?
What is NetworkOnMainThread Exception?
What happens next when the device switches between portrait and landscape?
How to copy database from assets folder in android using kotlin
How to check Android version?
What is the difference between match_parent and fill_parent?
Extract Date and Time from Long Type Variable - RRutors
What is Android?
What is Application?
How to Generate signed apk with android studio
What is Context?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Invoke-customs are only supported starting with android 0 --min-api 26