0

Is there any simple way to validate an email in kotlin without using firebase authentication? Need to validate an email before entering firebase.

Ex:- if a user fill the email field like abcdefg without @ need to display error message. if a user fill the email field like abc@gmail.com then those data will enter to the firebase.

like this:- (other fields like name, Phone number)

if (FullName.text.trim().isNotEmpty() && PhoneNo.length()
                    .equals(10) && PhoneNo.text.trim().isNotEmpty()){

}
else{

Toast.makeText(this, "fill all required details", Toast.LENGTH_LONG).show()

}

1 Answers1

0

You can write this function.

private fun isItEmail(email: String): Boolean {
        return !TextUtils.isEmpty(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches()
    }

then call isItEmail("yourEmail@email.com") function with your email string. If it return true, then it is a valid email like yourEmail@email.com else it return false then you can Toast it is not valid email.

Rezaul Islam
  • 603
  • 9
  • 12