Android 表单验证开源框架 saripaar
2015-04-20 17:38
471 查看
下载地址:
https://github.com/ragunathjawahar/android-saripaar
சரிபார் - sari-paar (Tamil for "to check", "verify" or "validate")
Android Saripaar is a simple, yet powerful rule-based UI validation library for Android. It is the SIMPLESTvalidation library available for Android.
Declarative style validation powered by Annotations.
Extensible
Synchronous and Asynchronous validations, you don't have to worry about threading.
Works with Stock Android Widgets, no custom view dependencies.
Quick to setup, just download the jar and include it in your
folder.
Isolates validation logic using rules.
Compatible with other annotation frameworks such as AndroidAnnotations, RoboGuice,
etc.,
Step 1 - Annotate your widgets using Saripaar
Annotations
The annotations are self-explanatory. The
validations will be performed by the library.
每个规则都是顾名思义的,其中
Step 2 - Instantiate a new Validator
You will need a
receiving callbacks on validation events.
Step 3 - Implement a ValidationListener
you receive the
failed.
Step 4 - Validate
The
You can run validations on a background
Validator.validate() 发起验证,并通过 ValidationListener 来通知验证结果。调用函数
Please visit the wiki for a complete guide on Android Saripaar.
https://github.com/ragunathjawahar/android-saripaar
Android Saripaar
சரிபார் - sari-paar (Tamil for "to check", "verify" or "validate")
Android Saripaar is a simple, yet powerful rule-based UI validation library for Android. It is the SIMPLESTvalidation library available for Android.
Why
Android Saripaar?
Declarative style validation powered by Annotations.Extensible
Synchronous and Asynchronous validations, you don't have to worry about threading.
Works with Stock Android Widgets, no custom view dependencies.
Quick to setup, just download the jar and include it in your
libsproject
folder.
Isolates validation logic using rules.
Compatible with other annotation frameworks such as AndroidAnnotations, RoboGuice,
etc.,
Quick
Start
Step 1 - Annotate your widgets using SaripaarAnnotations
@Required(order = 1) @Email(order = 2) private EditText emailEditText; @Password(order = 3) @TextRule(order = 4, minLength = 6, message = "Enter at least 6 characters.") private EditText passwordEditText; @ConfirmPassword(order = 5) private EditText confirmPasswordEditText; @Checked(order = 6, message = "You must agree to the terms.") private CheckBox iAgreeCheckBox;
The annotations are self-explanatory. The
orderattribute is mandatory and specifies the order in which the
validations will be performed by the library.
每个规则都是顾名思义的,其中
order 属性是必须的,用来告诉Saripaar这些输入规则的验证顺序。
Step 2 - Instantiate a new Validator
public void onCreate() { super.onCreate(); // Code… validator = new Validator(this); validator.setValidationListener(this); // More code… }
You will need a
Validatorand a
ValidationListenerfor
receiving callbacks on validation events.
Step 3 - Implement a ValidationListener
public class RegistrationActivity implements ValidationListener { public void onValidationSucceeded() { Toast.makeText(this, "Yay! we got it right!", Toast.LENGTH_SHORT).show(); } public void onValidationFailed(View failedView, Rule<?> failedRule) { String message = failedRule.getFailureMessage(); if (failedView instanceof EditText) { failedView.requestFocus(); ((EditText) failedView).setError(message); } else { Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } } }
onValidationSucceeded()- Called when all your views pass all validations.
onValidationFailed(View, Rule<?>)- Called when a
Rulefails,
you receive the
Viewalong with the
Rulethat
failed.
Step 4 - Validate
registerButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { validator.validate(); } });
The
Validator.validate()call runs the validations and returns the result via appropriate callbacks on the
ValidationListener.
You can run validations on a background
AsyncTaskby calling the
Validator.validateAsync()method.
Validator.validate() 发起验证,并通过 ValidationListener 来通知验证结果。调用函数
Validator.validateAsync()可以在一个AsyncTask中发起验证。
Maven
<dependency> <groupId>com.mobsandgeeks</groupId> <artifactId>android-saripaar</artifactId> <version>1.0.2</version> </dependency>
Gradle
dependencies { compile 'com.mobsandgeeks:android-saripaar:1.0.2' }
Wiki
Please visit the wiki for a complete guide on Android Saripaar.
License
Copyright 2012 Mobs and Geeks Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
相关文章推荐
- Android框架之Android Validation表单验证框架
- android 优秀开源框架表单
- android-saripaar:Android UI输入验证框架
- android-saripaar:Android UI输入验证框架
- android非空等格式验证框架android-saripaar地址
- Android框架之Android Validation表单验证框架
- 开源框架Android-Query 实现https自签名ssl证书验证
- Android之EditText表单验证框架
- Android 表单验证框架:AValidations
- Android 开源框架ActionBarSherlock 和 ViewPager 仿网易新闻客户端
- Android studio instant run对部分开源框架不支持问题解决
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
- Android酷炫开源框架
- MPAndroidChart开源图表框架—-柱状图(二)
- Android中常用的优秀开源框架
- Android酷炫实用的开源框架(UI框架)
- Android 开源框架Universal-Image-Loader解析--- 基本介绍及使用
- Android(java)学习笔记214:开源框架的文件上传(只能使用Post)
- 使用开源框架android-async-http提交数据