ohos-validation-komensky : A simple library for validating user input in forms using annotations.
A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the sample/ folder.
First, annotate your views like this:
@NotEmpty(messageId = R.string.validation_name)
@MinLength(value = 3, messageId = R.string.validation_name_length, order = 2)
private EditText mNameEditText;
Now you are ready to:
FormValidator.validate(this, new SimpleErrorPopupCallback(this, true, element));
You will receive collection of all failed validations in a callback and you can present them to the user as you want.
Or simply use prepared callbacks (like SimpleErrorPopupCallback
).
To start and stop live validation, simply call:
FormValidator.startLiveValidation(this, formContainer, new SimpleErrorPopupCallback(this, false, element));
FormValidator.stopLiveValidation(this);
Validations supported out of the box:
@NotEmpty(messageId = R.string.validation_name, order = 1)
private EditText mNameEditText;
@MinLength(value = 1, messageId = R.string.validation_participants, order = 2)
private EditText mNameEditText;
@MinValue(value = 2L, messageId = R.string.validation_name_length)
private EditText mEditNumberOfParticipants;
@MinNumberValue(value = "5.5", messageId = R.string.validation_name_length)
private EditText mEditPotentialOfHydrogen;
@RegExp(value = EMAIL, messageId = R.string.validation_valid_email)
private EditText mEditEmail;
@RegExp(value = "^[0-9]+$", messageId = R.string.validation_valid_count)
private EditText mEditCount;
@DateInFuture(messageId = R.string.validation_date)
private TextView mTxtDate;
@DateNoWeekend(messageId = R.string.validation_date_weekend)
private TextView mTxtDate;
@Custom(value = MyVeryOwnValidator.class, messageId = R.string.validation_custom)
private EditText mNameEditText;
For using ohos-validation-komensky module in your sample application, add below dependencies:
dependencies {
implementation project(':library')
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
}
For using ohos-validation-komensky in separate application, add the below dependencies and include "library.har" in libs folder of "entry" module :
dependencies {
implementation files('libs/library.har')
}
For using ohos-validation-komensky from a remote repository in separate application, add the below dependencies in build.gradle of "entry" module :
dependencies {
implementation 'io.openharmony.tpc.thirdlib:ohos-validation-komensky:1.0.1'
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。