# Android Form EditText
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.
# Example App
I built an example app that showcase some of the possibilities of the library.
You'll be able to find the app in the [Play Store](https://play.google.com/store/apps/details?id=com.andreabaccega.edittextformexample)
Here some screenshot of the Example app ( and the library )
![Examples list](http://lh6.ggpht.com/mYceoyXym2U4-6tRJWsudY4-6-V1TyFlqDfzL9P2R4Z059WZQLTZ3C9Gqcwr-hRrDQ) - ![Email validation](http://lh6.ggpht.com/yTzsI6-9VTtJVH331EA6gKc4GRBMv_DXxjAqPPlV9Yj5g-VGzcWtJ77T_m2JcbmbOoQ)
The app source code is located under this repo!
# How to include it
This library can be found in maven central repo. If you're using Android studio you can include it by writing the following in the corresponding _dependencies_ block
#### Gradle:
```groovy
dependencies {
// ...
compile 'com.andreabaccega:android-form-edittext:1.0.5'
// ...
}
```
####Maven
```xml
<dependency>
<groupId>com.andreabaccega</groupId>
<artifactId>android-form-edittext</artifactId>
<version>${com.andreabaccega.android-form-edittext-version}</version>
<type>aar</type>
<scope>provided</scope>
</dependency>
```
# How to use
In your xml import an extra namespace on the root of your layout
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
....
<!-- Your actual layout -->
....
</LinearLayout>
```
**Note:** It's not mandatory to use it on the root element. Also remember to change the xmlns value with your package name
Whenever you need to use the FormEditText just do the following in your xml.
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Some stuff -->
<com.andreabaccega.widget.FormEditText
whatever:testType="alpha"
android:id="@+id/et_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!-- Some other stuff -->
</LinearLayout>
```
As you noticed there is a *whatever:test* attribute setted to *alpha*. This let the FormEditText know that the data inside it should be only Alpha characters.
There are several values you can set to the test attribute:
- **regexp**: for custom regexp
- **numeric**: for an only numeric field
- **alpha**: for an alpha only field
- **alphaNumeric**: guess what?
- **personName**: checks if the entered text is a person first or last name.
- **personFullName**: checks if the entered value is a complete full name.
- **email**: checks that the field is a valid email
- **creditCard**: checks that the field contains a valid credit card using [Luhn Algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm)
- **phone**: checks that the field contains a valid phone number
- **domainName**: checks that field contains a valid domain name ( always passes the test in API Level < 8 )
- **ipAddress**: checks that the field contains a valid ip address
- **webUrl**: checks that the field contains a valid url ( always passes the test in API Level < 8 )
- **date**: checks that the field is a valid date/datetime format ( if customFormat is set, checks with customFormat )
- **nocheck**: It does not check anything except the emptyness of the field.
For most of the test type values this library comes with a couple of default strings. This means that error strings ( english only ) are already available for the following test types: numeric, alpha, alphanumeric
You can customize them using the attributes
- **testErrorString** used when the field does not pass the test
- **emptyErrorString** used when the field is empty
### Example:
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Some stuff -->
<com.andreabaccega.widget.FormEditText
whatever:testType="alpha"
whatever:emptyErrorString="@string/your_name_cannot_be_empty"
whatever:testErrorString="@string/your_name_is_ugly"
android:id="@+id/et_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!-- Some other stuff -->
</LinearLayout>
```
Furthermore you can ask the FormEditText to allow the content to be *optional*.
Just use the **emptyAllowed** attribute and set it to *true*. **Note:** If you don't specify the **emptyAllowed** attribute the default value is *false*.
If you want to use **regexp** as **test** attribute value you'll need to also use the **customRegexp** attribute. Take a look in the following example:
### Example: (Email check)
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Some stuff -->
<com.andreabaccega.widget.FormEditText
whatever:testType="regexp"
whatever:customRegexp="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
whatever:testErrorString="@string/error_emailnotvalid"
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_email"
android:inputType="textEmailAddress"
/>
<!-- Some other stuff -->
</LinearLayout>
```
**Note:** The library supports the email check natively using the **email** value as the **test** attribute.
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Some stuff -->
<com.andreabaccega.widget.FormEditText
whatever:testType="email"
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_email"
android:inputType="textEmailAddress"
/>
<!-- Some other stuff -->
</LinearLayout>
```
In your Java code you'll need to call a method when you want to know if the field validates.
```java
public void onClickNext(View v) {
FormEditText[] allFields = { etFirstname, etLastname, etAddress, etZipcode, etCity };
boolean allValid = true;
for (FormEditText field: allFields) {
allValid = field.testValidity() && allValid;
}
if (allValid) {
// YAY
} else {
// EditText are going to appear with an exclamation mark and an explicative message.
}
}
```
Calling *testValidity()* will cause the EditText to cycle through all the validators and call the isValid method. it will stop when one of them returns false or there are no validators left.
Furthermore *testValidity()* will also place an exclamation mark on the right of the [EditText](http://developer.android.com/reference/android/widget/EditText.html) and will call the [setError](http://developer.android.com/reference/android/widget/TextView.html#setError) method.
## Add your custom validators
You can add your custom validators runtime through the *addValidator* method. For example, let's suppouse we want to add a validator that checks that the text input is equal to the string "ciao":
```jav
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android Form EditText 验证输入合法性的编辑框.zip项目安卓应用源码下载Android Form EditText 验证输入合法性的编辑框.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android Form EditText 验证输入合法性的编辑框.zip (88个子文件)
Android Form EditText 验证输入合法性的编辑框
Android Form EditText 验证输入合法性的编辑框
android-edittext-validator-master
.gitignore 363B
settings.gradle 38B
build.gradle 0B
library
AndroidManifest.xml 301B
res
values-fr
strings.xml 1009B
values-ja
strings.xml 1KB
values-it
strings.xml 1KB
values-es
strings.xml 991B
values-de
strings.xml 1KB
values
fet_attrs.xml 1021B
strings.xml 1KB
build.gradle 2KB
src
com
andreabaccega
widget
DefaultEditTextValidator.java 11KB
ValidatingEditTextPreference.java 5KB
FormEditText.java 5KB
EditTextValidator.java 2KB
formedittextvalidator
SameValueValidator.java 703B
EmptyValidator.java 451B
IpAddressValidator.java 785B
MultiValidator.java 830B
EmailValidator.java 856B
AlphaNumericValidator.java 208B
OrValidator.java 686B
DateValidator.java 1KB
PersonNameValidator.java 274B
AlphaValidator.java 187B
PhoneValidator.java 724B
DomainValidator.java 396B
WebUrlValidator.java 521B
NumericValidator.java 483B
DummyValidator.java 362B
PersonFullNameValidator.java 283B
NotValidator.java 491B
Validator.java 694B
PatternValidator.java 751B
CreditCardValidator.java 1KB
AndValidator.java 730B
RegexpValidator.java 361B
proguard-project.txt 781B
.classpath 356B
project.properties 584B
.settings
org.eclipse.jdt.ui.prefs 3KB
org.eclipse.jdt.core.prefs 23KB
.project 822B
LICENSE 1KB
exampleproject
AndroidManifest.xml 1KB
res
layout
example_date_custom.xml 373B
example_personfullname.xml 333B
layout_examplegeneric.xml 992B
example_creditcard.xml 404B
example_email.xml 404B
example_email_or_creditcard.xml 414B
example_phone.xml 393B
example_custom.xml 540B
example_nocheck.xml 410B
example_date.xml 323B
example_alpha.xml 324B
example_personname.xml 329B
example_ipaddress.xml 371B
example_domainname.xml 373B
example_regexp.xml 444B
example_weburl.xml 406B
example_numeric.xml 452B
example_phone_custommessages.xml 543B
example_allowempty.xml 437B
drawable-ldpi
ic_launcher.png 3KB
menu
menu.xml 196B
drawable-mdpi
ic_launcher.png 5KB
xml
pref_contact.xml 2KB
values-v11
themes.xml 122B
drawable-hdpi
ic_launcher.png 9KB
drawable-xhdpi
ic_launcher.png 14KB
values
strings.xml 5KB
themes.xml 307B
build.gradle 948B
src
com
andreabaccega
edittextformexample
CiaoValidator.java 445B
SettingsActivity.java 7KB
EditTextFormExampleActivity.java 4KB
utils
ListItem.java 323B
LayoutListItem.java 595B
SimpleListItem.java 449B
LayoutExampleActivity.java 2KB
EmailOrCreditCard.java 2KB
proguard-project.txt 781B
.classpath 356B
.settings
org.eclipse.jdt.core.prefs 173B
.project 822B
README.md 10KB
共 88 条
- 1
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 计算机视觉课程设计-基于Chinese-CLIP的图文检索系统Python实现源码+文档说明
- 计算机视觉Python课程设计-基于Chinese-CLIP的图文检索系统源码+文档说明
- 基于网络分析与元胞自动机构建难民迁移模型及其政策建议
- 欧洲难民危机下基于动态网络规划模型与系统动力学的优化难民迁移策略
- 基于时间约束函数的埃及水资源稀缺度模型与干预提案
- 全球水资源短缺与海地水危机的多学科分析和干预计划研究
- 印度水资源预测与干预政策分析:基于多元线性回归模型的技术研究与应用
- 微信小程序点餐系统微信小程序开发实战项目源码+数据库+详细文档说明(高分项目)
- Flutter jar包
- 基于微信平台的点餐系统小程序完整源码+文档说明+数据库(高分毕业设计项目)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功