模式匹配以验证在 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}" + ")+");
模式匹配以验证在 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}" + ")+");
试试这个:它对我来说运行良好。
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
享受 。
使用以下功能验证电子邮件 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();
}
正则表达式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();
}
使用以下方法检查有效的电子邮件 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;
}