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 libs project
    folder.
  • Isolates validation logic using rules.
  • Compatible with other annotation frameworks such as AndroidAnnotationsRoboGuice,
    etc.,

Quick
Start

Step 1 - Annotate your widgets using Saripaar
Annotations

@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 order attribute is mandatory and specifies the order in which the
validations will be performed by the library.

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 Validator and a ValidationListener for
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 Rule fails,
    you receive the View along with the Rule that
    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 AsyncTask by calling theValidator.validateAsync() method.

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.
时间: 2024-08-04 03:48:58

Android 表单验证开源框架 saripaar的相关文章

CI框架表单验证实例详解_php实例

本文实例讲述了CI框架表单验证的方法.分享给大家供大家参考,具体如下: 1.form头部信息的自动输出函数(view) <?php $attributes = array('class' => 'email', 'id' => 'myform'); echo form_open('email/send', $attributes); //上面一行代码输出: //<form method="post" accept-charset="utf-8"

Yii框架中jquery表单验证插件用法示例_php实例

本文实例讲述了Yii框架中jquery表单验证插件用法.分享给大家供大家参考,具体如下: 运行效果图如下: 视图层: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtm

Laravel 5框架学习之表单验证_php实例

在建立一个文章的时候,如果你什么都不输入直接提交,ok,你获得了一个空的文章,没有任何错误提示,这是不对的.在命令行下运行 php artisan 可以看到一个选项 make:request,新建一个form request类.在命令行执行 复制代码 代码如下: php artisan make:request CreateArticleRequest 生成的文件在 app/http/requests 目录下.在文件中我们可以看到两个方法: public function authorize()

表单验证之PHP代码框架

   我在上一篇文章中讲到使用javascript做集成表单验证的方法,对于客户端验证已经足够,但好的表单验证应同时在客户端和服务器端进行--这正是写本文的目的.     如果采用一般的验证方法应该怎样写呢?     if ($_POST['some'] 不满足 condition) {              die("wrong");     }     类似于javascript的集成验证方法,在PHP中也可利用数组和eval语句实现表单验证(服务器端)框架.一般步骤:    

支持ASP.NET MVC、WebFroM的表单验证框架ValidationSuar使用介绍

  这篇文章主要介绍了支持ASP.NET MVC.WebFroM的表单验证框架ValidationSuar使用介绍,本文详细讲解了使用步骤,并给出一个完整Demo下载,需要的朋友可以参考下 1.支持javascript端和后端的双重验证 (前端目前依赖于jquery.validate.js,也可以自已扩展) 2.代码简洁 3.调用方便 4.功能齐全 使用方法: 新建初始化类,将所有需要验证的在该类进行初始化,语法相当简洁并且可以统一管理,写完这个类你的验证就完成了70% 函数介绍: Add 默认

PHP Yii框架之表单验证规则大全_php实例

Yii是一个基于组件的高性能PHP框架,用于开发大型Web应用.Yii采用严格的OOP编写,并有着完善的库引用以及全面的教程. 废话不多说了,直接给大家贴代码了. <?php class ContactForm extends CFormModel { public $_id; public $contact;//联系人 public $tel;//电话 public $fax;//传真 public $zipcode;//邮编 public $addr;//地址 public $mobile;

tapestry 框架中 客户端表单验证后 如何判断是否验证成功 并当验证成功后调用我自己写的一个js函数

问题描述 tapestry框架中客户端表单验证后如何判断是否验证成功并当验证成功后调用我自己写的一个js函数谢谢

支持ASP.NET MVC、WebFroM的表单验证框架ValidationSuar使用介绍_实用技巧

1.支持javascript端和后端的双重验证 (前端目前依赖于jquery.validate.js,也可以自已扩展) 2.代码简洁 3.调用方便 4.功能齐全 使用方法: 新建初始化类,将所有需要验证的在该类进行初始化,语法相当简洁并且可以统一管理,写完这个类你的验证就完成了70% 函数介绍: Add 默认类型(邮件.手机.qq等) AddRegex 正则验证 在Add无法满足情部下使用 addFunc 使用js函数进行验证,一般用于业逻辑的验证 ,功能非常强大,可以满足各种验证(注意:add

CI框架表单验证实例详解

本文实例讲述了CI框架表单验证的方法.分享给大家供大家参考,具体如下: 1.form头部信息的自动输出函数(view) <?php $attributes = array('class' => 'email', 'id' => 'myform'); echo form_open('email/send', $attributes); //上面一行代码输出: //<form method="post" accept-charset="utf-8"