This question already has an answer here:
- How should I validate an e-mail address? 31 answers
How can we perform Email Validation
on edittext
in android
? I have gone through google & SO but I didn't find out a simple way to validate it.
This question already has an answer here:
How can we perform Email Validation
on edittext
in android
? I have gone through google & SO but I didn't find out a simple way to validate it.
To perform Email Validation we have many ways,but simple & easiest way are two methods.
1- Using
EditText(....).addTextChangedListener
which keeps triggering on every input in anEditText box
i.e email_id is invalid or valid2- Simplest method using
if-else
condition. Take the EditText box string using getText() and compare with pattern provided for email. If pattern doesn't match or macthes, onClick of button toast a message. It ll not trigger on every input of an character in EditText box . simple example shown below.I did this way:
Add this method to check whether email address is valid or not:
Now check with String of EditText:
Done
This is a sample method i created to validate email addresses, if the string parameter passed is a valid email address , it returns true, else false is returned.