Library that validate text of all android classes that extends TextView (EditText especially) It's simply extendable by adding new annotations,validators and validation methods.
@NotEmpty
private EditText mEditText
private Button mButton;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.activity_main);
mEditText = (EditText)findViewById(R.id.activity_main_edittext);
mButton = (Button)v.findViewById(R.id.activity_main_button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Validator validator = new Validator();
validator.validate(MainActivity.this);
}
});
}
@Email or @Email("text to set")
@NotEmpty or @NotEmpty("text to set")
@Number or @Number("text to set")
@Regex(value = "answer when not match", regex = "regex");
@ValueGreaterThan(value = "this value must be greater than 2", number = 2)
@ValueLessThan(value = "this value must be less than 3", number = 3)
One thing you have to do is:
- create annotation
- create validator
- add validator to Validators class the same way as the others are added.
You can simply use validators on any other class that implement Validatable interface.