ragunathjawahar / android-saripaar

UI form validation library for Android
Apache License 2.0
3.22k stars 460 forks source link

com.mobsandgeeks.saripaar.exception.SaripaarViolationException: 'com.monicalabbao.customvalidator.MobileNumber' requires the 'sequence' attribute. #156

Closed monicavaldez closed 8 years ago

monicavaldez commented 8 years ago

I created a custom annotation for validating a mobile number:

ProfileValidator.class

public class ProfileValidator extends Validator {

    public ProfileValidator(Object controller) {
        super(controller);
        registerAnnotation(MobileNumber.class);
    }
    @Override
    public void validate() {
        super.validate();
    }

}

MobileNumberRule.class

public class MobileNumberRule extends AnnotationRule<MobileNumber, String> {
     protected MobileNumberRule(MobileNumber mobileNumber) {
          super(mobileNumber);
     }
     @Override
     public boolean isValid(String s) {
         Log.d("MobileNumberRule", "" + Patterns.PHONE.matcher(s).matches());
         return Patterns.PHONE.matcher(s).matches();
     }
 }

MobileNumber.class

 @ValidateUsing(MobileNumberRule.class)
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.FIELD)
 public @interface MobileNumber {
     String message()    default "Please enter a valid mobile phone number.";
 } 

I am not sure if this is the right way to file this issue, or if it is an issue even. But can you please tell me what should I do, etc.

Thanks!

ragunathjawahar commented 8 years ago

The attributes message, messageResId and sequence are mandatory when you declare custom annotations.

@ValidateUsing(MobileNumberRule.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MobileNumber {
    @StringRes int messageResId()  default -1;
    String message()               default "Please enter a valid mobile phone number.";
    int sequence()                 default -1;
}