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.
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();
}
}
3 comments:
yeezy shoes
kyrie 5
cheap jordans
yeezy boost 350
yeezys
nike air max 95
air max
lebron james shoes
air max 270
nhl jerseys
Harrah's Resort Southern California Casino & Hotel - JDH Hub
Harrah's Resort Southern California Casino & Hotel in 경기도 출장마사지 Southern California offers an elegant and 부천 출장안마 luxurious resort experience for 김포 출장마사지 the 용인 출장샵 weary 경기도 출장마사지 traveler.
have a peek at this web-sitewhy not try here Get More InfoMore Info check my blogimportant source
Post a Comment