Here some method for check email id is valid or not
it will return "true" if email id is valid otherwise return "false",you can pass string on this function and get that string is valid email id or not
here some method that gives you passing string is contain valid email id or not
1).
public static boolean isEmailValid(String email) {
boolean isValid = false;
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
2).
booleancheckEmailCorrect(String Email) {
String pttn = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
Pattern p = Pattern.compile(pttn);
Matcher m = p.matcher(Email);
if (m.matches()) {
return true;
}
return false;
}
3).
public boolean isEmailValid(String email) {
boolean flag;
String expression ="[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{1,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{1,25}" +
")+" ;
CharSequence inputStr = email.trim();
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches())
flag = true;
else
{
flag=false;
}
return flag;
}
////////////////////////////////////////////////////////=====================
you can use this finction like below
if(isEmailValid("abc@abc.com"))
{
else
{
code for invalid email ids
}
{
do some code for valid email id
}else
{
code for invalid email ids
}
thanks
public final static boolean isValidEmail(CharSequence target) {
ReplyDeleteif (target == null) {
return false;
} else {
return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
}
check this.
go code written by you.Kunbhar Janhero Umerkot Sindh Pakistan Nadir Ali
ReplyDelete