Easy-Checker is the best Android validation library in GitHub with the easiest and fastest implementations
FreeEasy-Checker is a very simple input validation library for Android written in Kotlin and easily accessable from Java code as well. You will get many validation way or library. But most of them are not so easy for this simple task, that's why most of time time we go for legacy if else chain to check all the input fields, and we all know how distrubing is that.
Easy-Checker provides maven based easy installation
add this to your root build.gradle file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
add this dependency in your app level build.gradle file
implementation 'com.github.mkhan9047:Easy-Checker:1.0.2'
The main class is EasyChecker it's a singleton class that have a only one public function, validateInput(), It's super simple process, add tags in your input field, call the function with the possible parameters!
<EditText
android:id="@+id/firstEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:tag="Name"/>
<EditText
android:id="@+id/fourthEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm Password"
android:tag="Confirm Password">
try {
var isValidationSuccess = EasyChecker.validateInput(
MainActivity.this,
8,
PasswordPattern.PASSWORD_PATTERN_NONE,
firstNameEditText,
lastNameEditText,
emailEditText,
passwordEditText,
confrimPasswordEditText
)
/**you can either use the returned boolean or just do the implementaiton
here as errors are only thrown in exception blocks
**/
doSignUp()
//or
if(isValidationSuccess){
//if validated
doSignUp()
}else{
//if not validated
}
} catch (developerErrorException: DeveloperErrorException) {
//best approach to print in log
developerErrorException.printStackTrace()
} catch (inputErrorException: InputErrorException) {
//best approach is show this to user
Toast.makeText(
this,
inputErrorException.message,
Toast.LENGTH_LONG
).show()
}
There are two types of exceptions one is DeveloperException and another is InputErrorException, Those exceptions are basically checked exceptions, so you must have to catch both the exceptions.
DeveloperException: Basically this exception is thrown if the developer did any error during implementation of this library like not adding "Tag" in input field or Text field or Giving wrong parameters or else
InputErrorException: This exception is the main validation error done by user, you can get the actual message from the exception and show it to user, Like if one user didn't put the email field then he would get something like : "Email field can't be empty!" or what ever you like
I have worte a class with some popular password pattern Regex, Here are the Constants:
Want to contribute? Great! Make a pull requeset, and do your best, I will marge if it's good for others!
MIT License Copyright (c) 2019 Mujahid Khan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.