Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
com.andreabaccega:android-form-edittext
Advanced tools
An extension of EditText with data validation facilities
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.
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 Here some screenshot of the Example app ( and the library )
-
The app source code is located under this repo!
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
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
// ...
compile 'com.andreabaccega:android-edittext-validator:1.3.5'
// ...
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.andreabaccega</groupId>
<artifactId>android-edittext-validator</artifactId>
<version>${...}</version>
<type>aar</type>
<scope>provided</scope>
</dependency>
Since 1.3.+ the library comes with a new optional dependency: com.android.support.design. This will enable the new TextInputLayout features to be used with the validation engine. Version 1.3.+ depends on com.android.support.design:2.2.0 but if you're not using the support design library you can safely exclude it while including this with gradle by doing so:
dependencies {
// ..
implementation 'com.andreabaccega:android-form-edittext:1.3.5'
// ..
}
In your xml import an extra namespace on the root of your layout
<?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"
android:orientation="vertical">
....
<!-- 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 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"
android:orientation="vertical">
<!-- 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:
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
<?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"
android:orientation="vertical">
<!-- 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:
<?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 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"
android:orientation="vertical">
<!-- 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.
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 and will call the setError method.
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":
public class CiaoValidator extends Validator {
public CiaoValidator() {
super("You should enter 'ciao' here");
}
public boolean isValid(EditText et) {
return TextUtils.equals(et.getText(), "ciao");
}
}
As you can see in the constructor you'll be required to set an Error Message that will be handled ( in this simple scenario ) by the super class. That piece of code will set the error message to: You should enter 'ciao' here.
This means that if the user will not enter "ciao" in the edit text it will get that error message in the popup.
You can use the following binary operators in order to perform checks on the field value:
With these binary operator validators you'll be able to perform as many different checks as you want. For example, lets say you want a field to be valid either if the user enters his email address or his credit card. Use 'nocheck' in the xml and programmatically do something like this:
protected void onCreate(Bundle savedInstanceState) {
// Blabla
FormEditText fdt = (FormEditText) findViewById(R.id.et);
fdt.addValidator(
new OrValidator(
"This is neither a creditcard or an email",
new CreditCardValidator(null), // we specify null as the message string cause the Or validator will use his own message
new EmailValidator(null) // same here for null
)
);
}
FAQs
An extension of EditText with data validation facilities
We found that com.andreabaccega:android-form-edittext demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.