Android Email Validation On Edittext
I have one edittext and I would to to write email validation in my Editttext this is a xml code Copy
As suggested here.
Solution 2:
I am posting very simple and easy answer of email validation without using any string pattern.
1.Set on click listener on button....
button_resetPassword.setOnClickListener(newView.OnClickListener()
{
@OverridepublicvoidonClick(View v)
{
CharSequence temp_emilID=username.getText().toString();//here username is the your edittext object...if(!isValidEmail(temp_emilID))
{
username.requestFocus();
username.setError("Enter Correct Mail_ID ..!!");
or
Toast.makeText(getApplicationContext(), "Enter Correct Mail_ID", Toast.LENGTH_SHORT).show();
}
else
{
correctMail..
//Your action...
}
});
2.call the isValidEmail() i.e..
publicfinalstaticbooleanisValidEmail(CharSequence target)
{
if (TextUtils.isEmpty(target))
{
returnfalse;
} else {
return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
}
I hope it will helpful for you...
Solution 3:
Android Email Validation Simplest way
String validemail="[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}"+")+";
String emal=email.getText().toString();
Matcher matcherObj =Pattern.compile(validemail).matcher(emal);
if (matcherObj.matches()) {
Toast.makeText(getApplicationContext(), "enter
all details", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"please enter
valid email",Toast.LENGTH_SHORT).show();
}
Solution 4:
Try following code:
publicfinalstaticbooleanisValidEmail(CharSequence target) {
return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
This works fine.
Solution 5:
StringemailPattern="[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
if(emailId.getText().toString().isEmpty()) {
Toast.makeText(getApplicationContext(),"enter email address",Toast.LENGTH_SHORT).show();
else {
if (emailId.getText().toString().trim().matches(emailPattern)) {
Toast.makeText(getApplicationContext(),"valid email address",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),"Invalid email address", Toast.LENGTH_SHORT).show();
}
}
Post a Comment for "Android Email Validation On Edittext"