This is a simple example showing email validation in ANDROID.
This example uses regex for email validation.
Create a button and an edittext in your main.xml file and try this code.
package com.coderzheaven; import java.util.regex.Pattern; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class EmailValidationDemo extends Activity { EditText TF; public Button checkButton; public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile( "[a-zA-Z0-9+._%-+]{1,256}" + "@" + "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" + "(" + "." + "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" + ")+" ); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); TF=(EditText) findViewById(R.id.TF); checkButton=(Button) findViewById(R.id.checkButton); checkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String email=TF.getText().toString(); if(checkEmail(email)) Toast.makeText(EmailValidationDemo.this,"Valid Email Addresss", Toast.LENGTH_SHORT).show(); else Toast.makeText(EmailValidationDemo.this,"Invalid Email Addresss", Toast.LENGTH_SHORT).show(); } }); } private boolean checkEmail(String email) { return EMAIL_ADDRESS_PATTERN.matcher(email).matches(); } }
Check this link to find how you can send email from android programatically.
Please leave your valuable comments……
yeah! worked like a chram! (^_^) thank u so much!
Thank u so much.. but can u make it to complete file please,, so that the user can know about the exceptions in manifest file also
Hi,
I’m developing an android app where I’m storing encrypted password(md5) in database using php script. I can successfully insert encrypted password it in database but cannot check it with the value I’m entering in login form. So can you please tell me how to encrypt password in android?
Hi Shreya……
We will check that.
Hello Shreya, You can encrypt the password using the “Cipher” class in android.
Hello,
I have implemented the example and tested it, it was working fine in most cases, but when i tried to test abc.xyz@gmail , then it is showing “Valid Email Addresss”. I have not entered .com/.org/.co or any else still it is showing its valid.
ok TechnoTalkative..
We will rectify it.
Thanks for the information.
i am using abc@def@gmail.com it showing valid email..
OK Ranjtih we will check that. most probably we might have missed that combination.
ya in my came whatever m typing with @gamil.com its showing valid…otherwise invalid