标签:android style class code java http
简单易用的Android校验库。
Comming soon
Configuration conf = Configuration.buildIn(context, BuildInTypes.Required, "必填选项!");
conf.add(BuildInTypes.LengthInMax, 20);
conf.add(BuildInTypes.Email);
EditText edittext = (EditText) findViewById(R.id.single_test);
ResultWrapper result = FormValidator.testField(edittext, conf);
通过 View ID 来绑定校验配置信息
final FormValidator fv = new FormValidator();
// FormValidator.configFor(*Config instance*, *view id for EditText*)
fv.configFor(Configuration.buildIn(context, BuildInTypes.ChineseMobilePhone), R.id.form_field_1);
fv.configFor(Configuration.buildIn(context, BuildInTypes.CreditCard), R.id.form_field_2);
fv.configFor(Configuration.buildIn(context, BuildInTypes.Digits), R.id.form_field_3);
fv.configFor(Configuration.buildIn(context, BuildInTypes.Email), R.id.form_field_4);
fv.configFor(Configuration.buildIn(context, BuildInTypes.EqualTo, "chenyoca"), R.id.form_field_5);
fv.configFor(Configuration.buildIn(context, BuildInTypes.Host), R.id.form_field_6);
fv.configFor(Configuration.buildIn(context, BuildInTypes.HTTP_URL), R.id.form_field_7);
fv.configFor(Configuration.buildIn(context, BuildInTypes.LengthInMax, 5), R.id.form_field_8);
fv.configFor(Configuration.buildIn(context, BuildInTypes.LengthInMin, 4), R.id.form_field_9);
fv.configFor(Configuration.buildIn(context, BuildInTypes.LengthInRange, 4,8), R.id.form_field_10);
fv.configFor(Configuration.buildIn(context, BuildInTypes.NotBlank), R.id.form_field_11);
fv.configFor(Configuration.buildIn(context, BuildInTypes.Numeric), R.id.form_field_12);
fv.configFor(Configuration.buildIn(context, BuildInTypes.ValueInMax, 100), R.id.form_field_13);
fv.configFor(Configuration.buildIn(context, BuildInTypes.ValueInMin, 20.0), R.id.form_field_14);
fv.configFor(Configuration.buildIn(context, BuildInTypes.ValueInRange, 18, 30), R.id.form_field_15);
final LinearLayout form = (LinearLayout) findViewById(R.id.form);
// 1. 中断校验:按Layout的ChildView顺序校验,遇到校验失败则中断。
boolean passed = fv.testForm(form)
// 1. 连续校验:按Layout的ChildView顺序校验,遇到校验失败继续,不中断。
boolean passed = fv.testFormAll(form)
通过 Configuration的扩展接口,添加你自定义的校验实现类
// 1. 添加到已创建的Configuration中:
conf.add(new TestRunner("出错时,此消息被返回并显示到EditText中") {
@Override
public boolean test(CharSequence inputValue) {
// 校验通过时返回 true
return inputValue.equal("AABB");
}
});
// 2. 通过自定义TestRunner创建Configuration:
Configuration.custom(context, new TestRunner("出错时,此消息被返回并显示到EditText中") {
@Override
public boolean test(CharSequence inputValue) {
return false;
}
})
开源Android校验库 - Android Validation,布布扣,bubuko.com
开源Android校验库 - Android Validation
标签:android style class code java http
原文地址:http://blog.csdn.net/chenyoca/article/details/34860675