Android表單輸入驗證庫:android-validation-komensky

jopen 10年前發布 | 47K 次閱讀 Android Android開發 移動開發

這是一個簡單的函數庫,使用注釋語法來驗證用戶輸入的表單信息。你僅可以驗證幾行代碼,且顯示的所有視圖都將反饋給用戶。它還帶有一個可擴展的在線驗證選項,這樣你就可以為定制視圖編寫自己的驗證信息及適配器了。
Android表單輸入驗證庫:android-validation-komensky

特性:

  • Validate all views at once and show feedback to user. With one line of code.
  • Live validation - check user input as he moves between views with immediate feedback.
  • Extensible library - you can add your own validations or adapters for custom views.

如何驗證

首先,在你的視圖中的注釋如下:

@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)); 

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).

Live validation

To start and stop live validation, simply call:

FormValidator.startLiveValidation(this, new SimpleErrorPopupCallback(this));  
FormValidator.stopLiveValidation(this); 

List of all supported validation annotations

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; 
@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; 

項目主頁:http://www.baiduhome.net/lib/view/home/1390789723929

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!