Android Check Library-android Validation
Easy-to-use Android Check library.
Built-in support for check mode
- Required (required)
- Notblank (Non-empty data)
- Digits (number only)
- Date Date
- Email Email
- Equalto (same as specified value)
- Host (Host address)
- Httpurl (Http URL)
- IPv4 (IPv4 address)
- Lengthinrange (Specify length range)
- Lengthinmin (Minimum length)
- Lengthinmax (Maximum length)
- Numeric Numerical
- CreditCard (Credit card number)
- Valueinrange (Maximum range)
- Valueinmin (Minimum value)
- Valueinmax (maximum value)
- Chinesemobilephone (China's mobile phone number)
How do I use it? Gradle on Android Studio
Comming soon
Method 1: Verify the individual EditText 1. Build a checksum configuration
"必填选项!"); 20); conf.add(BuildInTypes.Email);
2. Perform a check on the EditText
EditText edittext = (EditText) findViewById(R.id.single_test); ResultWrapper result = FormValidator.testField(edittext, conf);
Mode 2: All edittext in the entire layout
Binding the checksum configuration information through the View ID
1. Binding its checksum configuration to each edittext in the form
FinalFormvalidator FV =NewFormvalidator ();//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, -), 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, -, -), r.id.form_field_15);
2. Perform a check configuration within the form
final LinearLayout form = (LinearLayout) findViewById(R.id.form); // 1. 中断校验:按Layout的ChildView顺序校验,遇到校验失败则中断。 boolean passed = fv.testForm(form) // 1. 连续校验:按Layout的ChildView顺序校验,遇到校验失败继续,不中断。 boolean passed = fv.testFormAll(form)
How do I extend it?
Add your own custom validation implementation class through the configuration extension interface
//1. Add to the configuration you have created:Conf.add (NewTestrunner ("When an error occurs, this message is returned and displayed to EditText") {@Override Public Boolean Test(Charsequence Inputvalue) {//Check returns true on Pass returnInputvalue.equal ("AABB"); } });//2. Create a configuration from custom Testrunner:Configuration.custom (Context,NewTestrunner ("When an error occurs, this message is returned and displayed to EditText") {@Override Public Boolean Test(Charsequence Inputvalue) {return false; } })