· 6 years ago · Jun 10, 2019, 06:04 AM
1public boolean checkEmailValidity(AppCompatEditText emailFormat){
2
3 String getEmail = emailFormat.getText().toString();
4 boolean getEnd;
5
6 //CHECK STARTING STRING IF THE USER
7 //entered @gmail.com / @yahoo.com / @outlook.com only
8 boolean getResult = !TextUtils.isEmpty(getEmail) && android.util.Patterns.EMAIL_ADDRESS.matcher(getEmail).matches();
9
10 //CHECK THE EMAIL EXTENSION IF IT ENDS CORRECTLY
11 if (getEmail.endsWith("@gmail.com") || getEmail.endsWith("@yahoo.com") || getEmail.endsWith("@outlook.com")){
12 getEnd = true;
13 }else {
14 getEnd = false;
15 }
16
17 //TEST THE START AND END
18 return (getResult && getEnd);
19}