Home

Awesome

Android-Validator

Form Validator Library for Android

[Flattr this git repo](https://flattr.com/submit/auto?user_id=throrin19&url=https://github.com/throrin19/Android-Validator/&title=Android Validator&language=Java&tags=github&category=software)

Presentation

Form Validator Library for Android is based on Zend_Validator coded in PHP. This library is intended to simplify and streamline the code to validate a form Android. For the moment, the form can just handle the EditText. Other elements will emerge in future versions.

License

Requirement

Organization

Import in your Project

Graddle Project

Comming Soon

Maven Project

Comming Soon

Testing

In order to execute tests:

gradle localTest

Results are available in app/build/reports/tests/index.html

Use

Form Validator Library is composed of 3 members :

Validator

The validator is basic class for this library. It contains specific validation rules. To instanciate validator, you just have to do this (EmailValidator for example):

new EmailValidator(context);

For some validators, functions can change the validation rules. The validator currently contains three basic validation rules:

public class CustomValidator extends AbstractValidator
{
    private int mErrorMessage = R.string.validator_custom; // Your custom error message

    public CustomValidator(Context c) {
        super(c);
    }

    @Override
    public boolean isValid(Object value) {
        // Your validation Test is here.
        // Retour true if it's correct, false if it's incorrect
        return true;
    }

    @Override
    public String getMessage() {
        return mContext.getString(mErrorMessage);
    }
}

Validate

The pure Validate class is a FIFO validator. It's test a list of AbstractValidator for specific EditText. For some special cases, Validate is not enough. This is why there are specific validates. This is why there are two individuals with a Validate operation different from that base :

Basicly, Validate can only handle a single EditText. If you want to manage several at the same time, see if **ConfirmValidate ** or **OrTwoRequiredValidate ** match your problem. If this is not the case, you may need to create your own Validate. To instantiate a Validate, you just have to do this:

Validate emailField = new Validate(email);

And to add Validator stack, for example to add a required Email field, you have to do this:

emailField.addValidator(new NotEmptyValidator(mContext));
emailField.addValidator(new EmailValidator(mContext));

Form

The Form class is the class teacher of the whole Library. It is this which manages the processing of each Validate, Validator and displays the error on the EditText automatically. The Form class stores a Validate stack and then you just have to run the validation with the validate() function. To instanciate Form and add Validates, you have to do this :

Form mForm = new Form();
mForm.addValidates(emailField);
mForm.addValidates(confirmFields);
mForm.addValidates(urlField);

// ...

// Launch Validation
if(mForm.validate()){
    // success statement
}else{
    // error statement like toast, crouton, ...
}

You can close the error using the form. Can close all errors or just one :

// close one error
mForm.closeError(emailField);
// close all errors
mForm.closeAllErrors()

Contrbute

Changelog

Contributors