![]() |
![]() |
![]() |
![]() |
|---|
Add maven jitpack.io and dependencies in build.gradle (Project) :
// build.gradle project
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/module
dependencies {
...
implementation 'com.github.gzeinnumer:AndroidFormValidation:version'
implementation 'com.google.android.material:material:1.2.0'
}- Material.io (docs)
First Step. Use MaterialComponents in your style :
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>- Import and start validation with make and object from class
Validator.
//import com.gzeinnumer.afv.Validator;
TextInputLayout formNamaParent = findViewById(R.id.form_nama_p);
TextInputEditText formNama = findViewById(R.id.form_nama);
Button btnSubmit = findViewById(R.id.btn_submit);
Validator validator = new Validator();
//Add your form that you want to validate.
//Add `EditText` or `TextInputEditText` to `validator`.
validator.addView(formNama); // Default TypeForm.TEXT
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean result = validator.validate();
//true if validate success
//false if validate failed
if (result) {
Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Not Done", Toast.LENGTH_SHORT).show();
}
}
});- Delete
form viewfrom validate process
Put your EditText or TextInputEditText to removeView(view).
validator.removeView(formNama);- Add view with custom configuration
//example 1
//Add `EditText` or `TextInputEditText` with custom `Rule`.
validator.addView(
formNama,
new Rule(TypeForm.EMAIL)
);
//example 2
//Add `EditText` or `TextInputEditText` with `TextInputLayout`.
validator.addView(
new FormInput(formNamaParent, formNama)
); // Default TypeForm.TEXT
//example3
//Add `EditText` or `TextInputEditText` with `TextInputLayout` and custom `Rule`.
validator.addView(
new FormInput(formNamaParent, formNama),
new Rule(TypeForm.TEXT)
);Read More Custom Rule
![]() |
![]() |
|---|---|
| Example 1 | Example 2 & Example 3 |
FullCode MainActivity & XML & Preview .
- Import and start validation with make and object from class
ValidatorRealTime.
TextInputEditText formUserName = = findViewById(R.id.form_username);
TextInputLayout formUserNameParent = findViewById(R.id.form_username_p);
Button btnSubmit = findViewById(R.id.btn_submit);
ValidatorRealTime validatorRealTime = new ValidatorRealTime();
validatorRealTime.addView(
new FormInput(formUserNameParent, formUserName)
); // Default TypeForm.TEXT
validatorRealTime.build();
//Validate Realtime
validatorRealTime.observer(new ValidatorCallBack() {
@Override
public void result(boolean isDone) {
//true if validate success
//false if validate failed
btnSubmit.setEnabled(isDone);
}
});
//Trigger with onClickListener
btnValidate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean result = validatorRealTime.getResult();
//true if validate success
//false if validate failed
if (result){
Toast.makeText(SecondActivity.this, "Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SecondActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
}
});- Delete
form viewfrom validate process
Put your EditText or TextInputEditText to removeView(view).
validatorRealTime.removeView(formNama);- Realtime message error when focus changed.
Put this code before build().
validatorRealTime.setEnableRealtimeMessageError(true); //default value is false- Add view with custom configuration
//example 1
//Add `EditText` or `TextInputEditText` with custom `Rule`.
validatorRealTime.addView(
formUserName,
new Rule(TypeForm.EMAIL)
);
//example 2
//Add `EditText` or `TextInputEditText` with `TextInputLayout`.
validatorRealTime.addView(
new FormInput(formUserNameParent, formUserName)
); // Default TypeForm.TEXT
//example3
//Add `EditText` or `TextInputEditText` with `TextInputLayout` and custom `Rule`.
validatorRealTime.addView(
new FormInput(formUserNameParent, formUserName),
new Rule(TypeForm.TEXT)
);Read More Custom Rule
![]() |
![]() |
|---|
FullCode SecondActivity & XML & Preview .
ArrayList<EditText> v = new Validator().getAllEditText();- 1.0.0
- First Release
- 1.0.1
- Add TEXT_NO_SYMBOL
- 1.0.4
- Support TextInputLayout
- 1.0.5
- Support Delete
- 1.0.6
- Bug Fixing
- 1.1.6
- Add Feature Disable Start With Space
- 1.1.7
- Bug Fixing
- 2.0.0
- Support SDK 16
- 2.1.0
- TEXT_NO_SYMBOL with permit some symbol
- 2.1.1
- Get All EditText
- 2.1.2
- Message
You can sent your constibution to branch open-pull.
Copyright 2020 M. Fadli Zein







