Android 电子邮件验证器,不会收到 ac.uk 电子邮件
Android email validators, wont pick up an ac.uk email a
为了注册用户,我希望他们能够使用以 .ac.uk 结尾的学生电子邮件地址,但我尝试了一些 emailCharacter 字符串,但总是返回无效的电子邮件地址。
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[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}" +
")+";
// "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]";
//If empty display error
if (entry.isEmpty()) {
regEmail.setError("Email field cannot be empty");
return false;
//If email address does not follow constraints
} else if (!entry.matches(emailCharacters)) {
regEmail.setError("Invalid email address");
return false;
更新:
//Validation for email
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[a-zA-Z0-9+._%-+]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"." +
"[a-zA-Z0-9]{0,25}" +
"."+
"[a-zA-Z0-9]{0,25}" + // add these item more in your regex
")+";
尝试使用 android.util.Patterns.EMAIL_ADDRESS.matcher(entry).matches()
将您的正则表达式更改为:
要尝试您的正则表达式,请使用此 https://regex101.com/
//regex for conditions .ac.uk
[a-zA-Z0-9+._%-+]{1,256}@[a-zA-Z0-9]{0,64}(.[a-zA-Z0-9]{0,25}.[a-zA-Z0-9]{0,25})
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[a-zA-Z0-9+._%-+]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"." +
"[a-zA-Z0-9]{0,25}" +
"."+
"[a-zA-Z0-9]{0,25}" + // add these item more in your regex
")+";
// "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]";
//If empty display error
if (entry.isEmpty()) {
regEmail.setError("Email field cannot be empty");
return false;
//If email address does not follow constraints
} else if (!entry.matches(emailCharacters)) {
regEmail.setError("Invalid email address");
return false;
} else if(entry.matches(emailCharacters))
return true;
}
为了注册用户,我希望他们能够使用以 .ac.uk 结尾的学生电子邮件地址,但我尝试了一些 emailCharacter 字符串,但总是返回无效的电子邮件地址。
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[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}" +
")+";
// "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]";
//If empty display error
if (entry.isEmpty()) {
regEmail.setError("Email field cannot be empty");
return false;
//If email address does not follow constraints
} else if (!entry.matches(emailCharacters)) {
regEmail.setError("Invalid email address");
return false;
更新:
//Validation for email
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[a-zA-Z0-9+._%-+]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"." +
"[a-zA-Z0-9]{0,25}" +
"."+
"[a-zA-Z0-9]{0,25}" + // add these item more in your regex
")+";
尝试使用 android.util.Patterns.EMAIL_ADDRESS.matcher(entry).matches()
将您的正则表达式更改为:
要尝试您的正则表达式,请使用此 https://regex101.com/
//regex for conditions .ac.uk
[a-zA-Z0-9+._%-+]{1,256}@[a-zA-Z0-9]{0,64}(.[a-zA-Z0-9]{0,25}.[a-zA-Z0-9]{0,25})
private Boolean validateEmail() {
String entry = regEmail.getEditText().getText().toString();
//Characters accepted for email address
String emailCharacters = "[a-zA-Z0-9+._%-+]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"." +
"[a-zA-Z0-9]{0,25}" +
"."+
"[a-zA-Z0-9]{0,25}" + // add these item more in your regex
")+";
// "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]";
//If empty display error
if (entry.isEmpty()) {
regEmail.setError("Email field cannot be empty");
return false;
//If email address does not follow constraints
} else if (!entry.matches(emailCharacters)) {
regEmail.setError("Invalid email address");
return false;
} else if(entry.matches(emailCharacters))
return true;
}