模式匹配以验证Edittext中输入的电子邮件ID。
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}" + ")+");
答案 0 :(得分:3)
试试这个:它对我来说运行良好。
Set Input Type "Email"
用于在XML文件中编辑文本。
public void Is_Valid_Email()
{
if(Email_Text.getText().toString()!=null)
{
if(isEmailValid(Email_Text.getText().toString())==false )
{
Toast.makeText(getApplicationContext(), "Invalid Email Address ",Toast.LENGTH_LONG).show();
Valid_Email=null;
}
else
{
Valid_Email=Email_Text.getText().toString();
}
}
else
{
Valid_Email=null;
}
}// end of email
// Android提供验证电子邮件地址的默认方法
boolean isEmailValid(CharSequence email)
{
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
} // end of email matcher
享受。
答案 1 :(得分:1)
使用以下功能验证电子邮件ID。
public boolean isValidEmailAddress(String emailAddress)
{
String expression="^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence inputStr = emailAddress;
Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
}
答案 2 :(得分:1)
答案 3 :(得分:0)
EMAIL ADDRESS VALIDATION
static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
String email = (EditText)findViewById(R.id.edittext);
if(!(_email.matches(EMAIL_PATTERN)))
{
Toast.makeText(getApplicationContext(),"Email is not valid", Toast.LENGTH_SHORT).show();
}
答案 4 :(得分:0)
使用以下方法检查有效的电子邮件ID。
/**
* method is used for checking valid email id format.
*
* @param email
* @return boolean true for valid false for invalid
*/
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;
}