1

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?

Kraiden
  • 567
  • 3
  • 18
  • 1
    Sorry, I goofed up. `@Optional` and `@Or` annotations were planned for the `2.1.0` release. They were not meant to be in the jars for `2.0.x`. – Ragunath Jawahar Oct 29 '15 at 06:12
  • Ha ha ha, I wondered if that was the case. Didn't seem to be plumbed in at all! Well, thanks for letting me know. Any suggestions in the meantime that don't involve a custom annotation, or is that pretty much my option? – Kraiden Oct 29 '15 at 20:35
  • 2
    You could use a `QuickRule`, less arduous than a custom annotation and register it with the validator. `mValidator.put(emailOrPhoneNumberEditText, emailOrPhoneNumberQuickRule)`. You can keep watching these issues - https://github.com/ragunathjawahar/android-saripaar/issues/61 and https://github.com/ragunathjawahar/android-saripaar/issues/120 – Ragunath Jawahar Oct 30 '15 at 01:38

0 Answers0