Reputation: 1307
why default EditText for email isn't validating an email Address?as EditText field is working for number input.i know that we can validate it by using java.util.regex.Matcher and java.util.regex.Pattern is there any default function as for number is?
inputtype="textEmailAddress" is not working as inputType="number" do work...
Upvotes: 2
Views: 5143
Reputation: 21107
You can do any type of validation in android very easily by the oval.jar file. OVal is a pragmatic and extensible general purpose validation framework for any kind of Java objects.
follow this link: http://oval.sourceforge.net/userguide.html
You can downlaod this from here: http://oval.sourceforge.net/userguide.html#download
You can use validation by setting tags in variables
public class Something{
@NotEmpty //not empty validation
@Email //email validation
@SerializedName("emailAddress")
private String emailAddress;
}
private void checkValidation() {
Something forgotpass.setEmailAddress(LoginActivity.this.dialog_email.getText().toString());
Validator validator = new Validator();
//collect the constraint violations
List<ConstraintViolation> violations = validator.validate(forgotpass);
if(violations.size()>0){
for (ConstraintViolation cv : violations){
if(cv.getMessage().contains("emailAddress")){
dialog_email.setError(ValidationMessage.formattedError(cv.getMessage(), forgotpass));
}
}
}
}
Upvotes: 0
Reputation: 22291
Please use below code for that, it will solve your problem.
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;
}
And see below Stack Overflow link for more information.
Upvotes: 0
Reputation: 24031
Editext field will not validate your email only by setting it's input method to email type.
You need to validate it yourself.
Try this:
Android: are there any good solutions how to validate Editboxes
Upvotes: 2