![]() | ![]() | ![]() | ![]() |
|---|
Add maven jitpack.io and dependencies in build.gradle (Project) :
// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
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 :
<stylename="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;TextInputLayoutformNamaParent = findViewById(R.id.form_nama_p);
TextInputEditTextformNama = findViewById(R.id.form_nama);
ButtonbtnSubmit = findViewById(R.id.btn_submit);
Validatorvalidator = newValidator();
//Add your form that you want to validate.//Add `EditText` or `TextInputEditText` to `validator`.validator.addView(formNama); // Default TypeForm.TEXTbtnSubmit.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(Viewv) {
booleanresult = validator.validate();
//true if validate success//false if validate failedif (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,
newRule(TypeForm.EMAIL)
);
//example 2//Add `EditText` or `TextInputEditText` with `TextInputLayout`.validator.addView(
newFormInput(formNamaParent, formNama)
); // Default TypeForm.TEXT//example3//Add `EditText` or `TextInputEditText` with `TextInputLayout` and custom `Rule`.validator.addView(
newFormInput(formNamaParent, formNama),
newRule(TypeForm.TEXT)
);Read More Custom Rule
![]() | ![]() |
|---|---|
| Example 1 | Example 2 & Example 3 |
FullCodeMainActivity&XML&Preview.
- Import and start validation with make and object from class
ValidatorRealTime.
TextInputEditTextformUserName = = findViewById(R.id.form_username);
TextInputLayoutformUserNameParent = findViewById(R.id.form_username_p);
ButtonbtnSubmit = findViewById(R.id.btn_submit);
ValidatorRealTimevalidatorRealTime = newValidatorRealTime();
validatorRealTime.addView(
newFormInput(formUserNameParent, formUserName)
); // Default TypeForm.TEXTvalidatorRealTime.build();
//Validate RealtimevalidatorRealTime.observer(newValidatorCallBack() {
@Overridepublicvoidresult(booleanisDone) {
//true if validate success//false if validate failedbtnSubmit.setEnabled(isDone);
}
});
//Trigger with onClickListenerbtnValidate.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(Viewv) {
booleanresult = validatorRealTime.getResult();
//true if validate success//false if validate failedif (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,
newRule(TypeForm.EMAIL)
);
//example 2//Add `EditText` or `TextInputEditText` with `TextInputLayout`.validatorRealTime.addView(
newFormInput(formUserNameParent, formUserName)
); // Default TypeForm.TEXT//example3//Add `EditText` or `TextInputEditText` with `TextInputLayout` and custom `Rule`.validatorRealTime.addView(
newFormInput(formUserNameParent, formUserName),
newRule(TypeForm.TEXT)
);Read More Custom Rule
![]() | ![]() |
|---|
FullCodeSecondActivity&XML&Preview.
ArrayList<EditText> v = newValidator().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 branchopen-pull.
Copyright 2020 M. Fadli Zein







