Android Saripaar-v2 OR annotation

1.1k Views Asked by At

So I have a field:

@NotEmpty
@Email
@Or
@Pattern(regex = "\\+?64(\\d{8,10})")
private EditText mETUser;

Basically, what I'm after is: The field can't be empty and must contain either a valid email OR a valid phone number (the Pattern.)

The OR annotation seems to be ignored though. If I enter a valid email, I get a failure on the @Pattern rule, and a valid phone number fails on the @Email rule.

I create the validator in the onCreate of my activity:

mValidator = new Validator(this);
mValidator.setValidationListener(this);

And validate the fields in an onClickListner with

mValidator.validate(false);

My callbacks are pretty basic at the moment:

@Override
public void onValidationSucceeded() {
    Log.d(TAG,"Validation passed");
}

@Override
public void onValidationFailed(List<ValidationError> errors) {
    Log.d(TAG, "Validation failed: ");
    for (ValidationError e : errors) {
        Log.d(TAG, "\tError: " + e.toString());
    }
}

I must be missing something, but I can't find any documentation on the OR annotation.

Any ideas?

0

There are 0 best solutions below