VTUFORUM
Form validation made easy in Android with saripaar - Printable Version

+- VTUFORUM (http://www.vtuforum.com)
+-- Forum: KnowledgeBase (/Forum-KnowledgeBase)
+--- Forum: Concepts and Tutorials (/Forum-Concepts-and-Tutorials)
+--- Thread: Form validation made easy in Android with saripaar (/Thread-Form-validation-made-easy-in-Android-with-saripaar)



Form validation made easy in Android with saripaar - Sandeep - 09-28-2015 10:03 AM

Hello geeks,

Most of us come across this scenario where we have to validate the form when we create it to check if the Email is correct or password is having minimum length, most of us check if the repeat password and password are of same length or not. Almost all do the same when they are using the library, if that is the case we have a library for that called saripaar.

https://github.com/ragunathjawahar/android-saripaar

This cool library find the validation errors and display it to user in quite stylish way.
Using this library is quite simple, open you gradle find dependencies and copy the following line

compile 'com.mobsandgeeks:android-saripaar:2.0.3'

Sync you Gradle, now you are all set to go for form validation

Assume that we have 2 EditText in the form like Email and Password and you want to validate them. Just we have to add simple annotations while declaring them in the activity.

Example:

@NotEmpty
@Email
private EditText edtMail;

@Password(min = 6)
private EditText edtPassword;

@ConfirmPassword
private EditText edtConfirm;


As we have see, it will check, if Email edittext is empty or what, it check if Email is in correct format, if password minimum length is 6 or not. You can enforce condition on password like alphanumneric or special symbol extra. We can check for confirming the password also. Similarly we can check other Form controls like checkbox etc.

You can find its whole documentation in above GitHub link along with the sample code. The Output it displays is in very stylish way. See the attached screenshots.

[attachment=222]

Have a nice coding Big Grin Big Grin