Convalida
Convalida
A simple, lightweight and powerful field validation library for Android.
Many Android applications has forms to be fulfilled by users and those forms requires some kind of validations, such as a required field or an email field, or a field that accepts only numeric values, etc.
Writing code to validate fields can be a repetitive and massive task, and it also can negatively impact development time.
Why Convalida?
  • You can use with Java Annotations
  • You can use with Android Data Dinding
  • You can use with a simple and lightweight Kotlin DSL
  • Reflection free
  • Compatible with other popular libraries such as ButterKinfe, Dagger 2, etc
  • Works with default Android widgets
How To Use?
With Annotations
Step 1 - Map the validations
  @Required(errorMessageResId = R.string.field_required)
  EditText nameField;

  @Email(errorMessageResId = R.string.invalid_email)
  EditText emailField;

  @OnlyNumber(errorMessageResId = R.string.only_numbers)
  EditText ageField;
Step 2 - Map the actions
  @ValidateOnClick Button validateButton;

  @ClearValidationsOnClick Button clearValidationsButton;
Step 3 - Map the results
  @OnValidationSuccess public void success() {
     /* All fields are valid */
  }

  @OnValidationError public void error() {
     /* Some field is invalid */
  }
Step 4 - Build project and initialize the generated class
  @Override public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_sample);
     // Same name of Activity or Fragment with suffix FieldsValidation
     SampleActivityFieldsValidation.init(this);
  }
With Data Binding
Step 1 - Map the validations
  <EditText
    android:id="@+id/name_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/name"
    app:requiredErrorMessage="@{@string/field_required}" />

  <EditText
    android:id="@+id/email_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/email"
    app:emailErrorMessage="@{@string/invalid_email}" />

  <EditText
    android:id="@+id/age_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/age"
    app:onlyErrorMessage="@{@string/only_numbers}" />
Step 2 - Map the actions
  <Button
    android:id="@+id/validate_button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/validate"
    app:validationAction="@{@id/validate}" />

  <Button
    android:id="@+id/clear_validations_button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/clear_validations"
    app:validationAction="@{@id/clear}" />
Step 3 - Map the results
  @OnValidationSuccess public void success() {
     /* All fields are valid */
  }

  @OnValidationError public void error() {
     /* Some field is invalid */
  }
Step 4 - Build project and initialize the generated class
   private ActivitySampleBinding binding;

   @Override public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     binding = DataBindingUtil.setContentView(this, R.layout.activity_sample);
     // Same name of Activity or Fragment with suffix FieldsValidation
     SampleActivityFieldsValidation.init(this, binding);
  }
With Kotlin Dsl
Step 1 - Just apply Convalida Kotlin DSL
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_sample)
    convalida {
      field(nameField) {
        isRequired(errorMessage = fieldRequiredErrorMessage)
      }
      field(emailField) {
        isEmail(errorMessage = invalidEmailErrorMessage)
      }
      field(ageField) {
        onlyNumber(errorMessage = onlyNumberErrorMessage)
      }
      validateOn(validateButton) {
        onSuccess { onValidationSuccess() }
        onError { onValidationError() }
      }
      clearValidationsOn(clearButton)
    }
  }

  fun onValidationSuccess() {
    /* All fields are valid */
  }

  fun onValidationError() {
    /* Some field is invalid */
  }
To use Convalida in your project, you need to add the following dependencies in your build.gradle:
dependencies {
   implementation 'io.github.wellingtoncosta:convalida-runtime:3.2.0'
   annotationProcessor 'io.github.wellingtoncosta:convalida-compiler:3.2.0'
}
These artifacts above contains all you need to use Convalida with Java Annotations or with Android Data Binding.
Note: If you're using Kotlin, you need to add kotlin-kapt plugin and use kapt instead of annotationProcessor.
Since version 3.0.0, we introduced a new feature that allows to use Convalida with a simple, lightweight and with no code generation Kotlin DSL.
If you want to use only the Convalida Kotlin DSL, just add the following dependency in your build.gradle:
dependencies {
   implementation 'io.github.wellingtoncosta:convalida-ktx:3.2.0'
}
Note: If you're using Convalida 3.0.0 or higher, you must have to use AndroidX artifacts and enable Jetifier in your project.
Required Validation
Required validation is applied when a field must have a non null or non empty value.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
Annotation:
  @Required(
    errorMessageResId = R.string.field_required,
    autoDismiss = true
  )
  EditText nameField;
Data Binding:
  <EditText
    android:id="@+id/name_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/name"
    app:requiredErrorMessage="@{@string/field_required}"
    app:requiredAutoDismiss="@{true}" />
Kotlin Dsl:
  val nameField = findViewById(R.id.name_field) as EditText
  val fieldRequired = "Field required"   convalida {
    field(nameField) {
      isRequired(errorMessage = fieldRequired)     }
  }
Email Validation
Email validation is applied when a field must accept only an email address.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Email(
    errorMessageResId = R.string.invalid_email,
    autoDismiss = true,
    required = true
  )
  EditText emailField;
Data Binding:
  <EditText
    android:id="@+id/email_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/email"
    app:emailErrorMessage="@{@string/invalid_email}"
    app:emailAutoDismiss="@{true}"
    app:emailRequired="@{true}" />
Kotlin Dsl:
  val emailField = findViewById(R.id.email_field) as EditText
  val invalidEmail = "Invalid email"   convalida {
    field(emailField) {
      isEmail(errorMessage = invalidEmail)     }
  }
Confirm Email Validation
Confirm email validation is applied when a field will confirm the email address filled in another email field.
Parameter Type Description
emailEditText android.widget.EditText This parameter represents the email field that have the original email address.
confirmEmailEditText android.widget.EditText This parameter represents the field that will confirm the email address filled in the original email field.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
Annotation:
  @ConfirmEmail(
    errorMessageResId = R.string.emails_not_match,
    autoDismiss = true
  )
  EditText confirmEmailField;
Data Binding:
  <EditText
    android:id="@+id/email_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/email" />

  <EditText
    android:id="@+id/confirm_email_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/confirm_email"
    app:confirmEmailEmailField="@{emailField}"
    app:confirmEmailErrorMessage="@{@string/emails_not_match}"
    app:confirmEmailAutoDismiss="@{true}" />
The app:confirmEmailEmailField receive as param a reference of an edit text that represents the email field that is fulfilled by user. In this case, we pass the reference of android:id="@+id/email_field" to app:confirmEmailEmailField.

Data Binding converts a separeted underscore notation to a camel case notation. Example: email_field to emailField.
Kotlin Dsl:
  val emailField = findViewById(R.id.email_field) as EditText
  val confirmEmailField = findViewById(R.id.confirm_email_field) as EditText
  val invalidEmailConfirmation = "Emails does not match"   convalida {
    field(confirmEmailField) {
      isConfirmEmail(
        emailField = emailField,
        errorMessage = invalidEmailConfirmation
      )
    }
  }
Length Validation
Length validation is applied when a field need to have a minimum and/or maximum length of characters.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
min int This parameter represents the minimum length of characters.
max int This parameter represents the maximum length of characters.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Length(
    errorMessageResId = R.string.invalid_length,
    min = 3,
    max = 10,
    autoDismiss = true,
    required = true
  )
  EditText lengthField;
Data Binding:
  <EditText
    android:id="@+id/length_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/length"
    app:lengthErrorMessage="@{@string/invalid_length}"
    app:lengthMin="@{3}"
    app:lengthMax="@{10}"
    app:lengthAutoDismiss="@{true}"
    app:lengthRequired="@{true}" />
Kotlin Dsl:
  val lengthField = findViewById(R.id.length_field) as EditText
  val invalidLength = "Invalid length"   convalida {
    field(lengthField) {
      withLength(min = 3, max = 10, errorMessage = invalidLength)
    }
  }
Numeric Limit Validation
Numeric limit validation is applied when a field must have a minimum and/or maximum numeric value.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
min java.lang.String This parameter represents the minimum numeric value. Internally this is converted to BigDecimal.
max java.lang.String This parameter represents the maximum numeric value. Internally this is converted to BigDecimal.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @NumberLimit(
    errorMessageResId = R.string.invalid_number,
    min = "0",
    max = "99",
    autoDismiss = true,
    required = true
  )
  EditText numberField;
Data Binding:
  <EditText
    android:id="@+id/number_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/number"
    app:numberLimitErrorMessage="@{@string/invalid_number}"
    app:numberLimitMin='@{"0"}'
    app:numberLimitMax='@{"99"}'
    app:numberLimitAutoDismiss="@{true}"
    app:numberLimitRequired="@{true}" />
Kotlin Dsl:
  val numericField = findViewById(R.id.number_field) as EditText
  val invalidNumericLimit = "Number exceeds the numeric limit"   convalida {
    field(numericField) {
      withNumericLimit(min = "0", max = "100", errorMessage = invalidNumericLimit)
    }
  }
Only Number Validation
Only number validation is applied when a field must accept only numeric values.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @OnlyNumber(
    errorMessageResId = R.string.only_numbers,
    autoDismiss = true,
    required = true
  )
  EditText onlyNumberField;
Data Binding:
  <EditText
    android:id="@+id/only_number_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/only_number"
    app:onlyNumberErrorMessage="@{@string/only_numbers}"
    app:onlyNumberAutoDismiss="@{true}"
    app:onlyNumberRequired="@{true}" />
Kotlin Dsl:
  val onlyNumberField = findViewById(R.id.only_number_field) as EditText
  val valueIsNotANumber = "Value is not a number"   convalida {
    field(onlyNumberField) {
      onlyNumber(errorMessage = valueIsNotANumber)
    }
  }
Pattern Validation
Pattern validation is applied when a field must accept values based on a regular expression.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
pattern java.lang.String This parameter represents the regular expression that will be applied on field value.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Pattern(
    pattern = MIXED_CAMEL_CASE,
    errorMessageResId = R.string.value_not_match,
    autoDismiss = true,
    required = true
  )
  EditText patternField;
Data Binding:
  <EditText
    android:id="@+id/pattern_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/pattern"
    app:patternPattern="@{Constants.MIXED_CAMEL_CASE}"
    app:patternErrorMessage="@{@string/value_not_match}"
    app:patternAutoDismiss="@{true}"
    app:patternRequired="@{true}" />
Kotlin Dsl:
  val patternField = findViewById(R.id.pattern_field) as EditText
  val valueDoesNotMatchPattern = "Value does not match the pattern"   convalida {
    field(patternField) {
      withPattern(pattern = PHONE_PATTERN, errorMessage = valueDoesNotMatchPattern)
    }
  }
Password Validation
Password validation is applied to a field that will be filled with an password value and the value can be a minimum length of characters and the value can also satisfy a regular expression.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
min int This parameter represents the minimum length of characters.
pattern java.lang.String This parameter represents the regular expression that will be applied on field value.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Password(
    pattern = MIXED_CASE_NUMERIC,
    min = 3,
    errorMessageResId = R.string.invalid_password,
    autoDismiss = true,
    required = true
  )
  EditText passwordField;
Data Binding:
  <EditText
    android:id="@+id/password_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/password"
    app:passwordMin="@{3}"
    app:passwordPattern="@{Constants.MIXED_CASE_NUMERIC}"
    app:passwordErrorMessage="@{@string/invalid_password}"
    app:passwordAutoDismiss="@{true}"
    app:passwordRequired="@{true}" />
Kotlin Dsl:
  val passwordField = findViewById(R.id.password_field) as EditText
  val invalidPassword = "Invalid password"   convalida {
    field(passwordField) {
      isPassword(min = 3, pattern = MIXED_CASE_NUMERIC, errorMessage = invalidPassword)
    }
  }
Confirm Password Validation
Confirm password validation is applied when a field will confirm the password filled in another password field.
Parameter Type Description
passwordEditText android.widget.EditText This parameter represents the password field that have the original password value.
confirmPasswordEditText android.widget.EditText This parameter represents the field that will confirm the password filled in the original password field.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
Annotation:
  @ConfirmPassword(
    errorMessageResId = R.string.passwords_not_match,
    autoDismiss = true
  )
  EditText confirmPasswordField;
Data Binding:
  <EditText
    android:id="@+id/password_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/password" />

  <EditText
    android:id="@+id/confirm_password_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/confirm_password"
    app:confirmPasswordPasswordField="@{passwordField}"
    app:confirmPasswordErrorMessage="@{@string/passwords_not_match}"
    app:confirmPasswordAutoDismiss="@{true}" />
The app:confirmPasswordPasswordField receive as param a reference of an edit text that represents the password field that is fulfilled by user. In this case, we pass the reference of android:id="@+id/password_field" to app:confirmPasswordPasswordField.

Data Binding converts a separeted underscore notation to a camel case notation. Example: password_field to passwordField.
Kotlin Dsl:
  val passwordField = findViewById(R.id.password_field) as EditText
  val confirmPasswordField = findViewById(R.id.confirm_password_field) as EditText
  val invalidPasswordConfirmation = "Invalid password confirmation"
  convalida {
    field(confirmPasswordField) {
      isConfirmPassword(passwordField = passwordField, errorMessage = invalidPasswordConfirmation)
    }
  }
Between Validation
Between validation is applied to a pair of fields where the value of the second field cannot be greater than the value of the first field.
Parameter Type Description
startEditText android.widget.EditText This parameter represents the first field of the pair
limitEditText android.widget.EditText This parameter represents the second field of the pair
startErrorMessage java.lang.String This parameter represents the error message that will be displayed when the value of first field is invalid.
limitErrorMessage java.lang.String This parameter represents the error message that will be displayed when the value of second field is invalid.
startAutoDismiss boolean This parameter means the error message will disappear automatically when the first field value is valid.
limitAutoDismiss boolean This parameter means the error message will disappear automatically when the second field value is valid.
Annotation:
  @Between.Start(
    key = 1,
    errorMessageResId = R.string.initial_period_not_valid,
    autoDismiss = true
  )
  EditText startField;

  @Between.Limit(
    key = 1,
    errorMessageResId = R.string.final_period_not_valid,
    autoDismiss = true
  )
  EditText limitField;
The key param is used only in annotations that serves a way to identify the pairs of fields during code generation in compile time.
Data Binding:
  <EditText
    android:id="@+id/start_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/start_value"
    app:betweenStartErrorMessage="@{@string/start_value_not_valid}"
    app:betweenStartAutoDismiss="@{true}"
    app:betweenLimitErrorMessage="@{@string/limit_value_not_valid}"
    app:betweenLimitAutoDismiss="@{true}"
    app:betweenLimitField="@{limitField}" />

  <EditText
    android:id="@+id/limit_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/limit_value" />
The app:betweenLimitField receive as param a reference of an edit text that represents the end field that is fulfilled by user. In this case, we pass the reference of android:id="@+id/final_period_field" to app:betweenLimitField.

Data Binding converts a separated underscore notation to a camel case notation. Example: limit_field to limitField.
Kotlin Dsl:
  val startField = findViewById(R.id.start_field) as EditText
  val limitField = findViewById(R.id.limit_field) as EditText
  val startValueNotValid = "Start value is invalid"
  val limitValueNotValid = "Limit value is invalid"
  convalida {
    between {
      start {
        field = startField
        errorMessage = startValueNotValid
      }
      end {
        field = finalPeriodField
        errorMessage = limitValueNotValid
      }
    }
  }
Credit Card Validation
Credit Card validation is applied to a field that will filled with a credit card number.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @CreditCard(
    errorMessageResId = R.string.invalid_credit_card,
    autoDismiss = true,
    required = true
  )
  EditText creditCardField;
Data Binding:
  <EditText
    android:id="@+id/credit_card_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/credit_card"
    app:creditCardErrorMessage="@{@string/invalid_credit_card}"
    app:creditCardAutoDismiss="@{true}"
    app:creditCardRequired="@{true}" />
Kotlin Dsl:
  val creditCardField = findViewById(R.id.credit_card_field) as EditText
  val invalidCreditCard = "Invalid credit card number"
  convalida {
    field(creditCardField) {
      isCreditCard(errorMessage = invalidCreditCard)
    }
  }
Cpf Validation
Cpf validation is applied to a field that will filled with a Brazillian Personal ID (Cadastro de Pessoa Física).
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Cpf(
    errorMessageResId = R.string.invalid_cpf,
    autoDismiss = true,
    required = true
  )
  EditText cpfField;
Data Binding:
  <EditText
    android:id="@+id/cpf_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/cpf"
    app:cpfErrorMessage="@{@string/invalid_cpf}"
    app:cpfAutoDismiss="@{true}"
    app:cpfRequired="@{true}" />
Kotlin Dsl:
  val cpfField = findViewById(R.id.cpf_field) as EditText
  val invalidCpf = "Invalid CPF"
  convalida {
    field(cpfField) {
      isCpf(errorMessage = invalidCpf)
    }
  }
Cnpj Validation
Cnpj validation is applied to a field that will filled with a Brazillian Company ID (Cadastro Nacional de Pessoa Jurídica).
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Cnpj(
    errorMessageResId = R.string.invalid_cnpj,
    autoDismiss = true,
    required = true
  )
  EditText cnpjField;
Data Binding:
  <EditText
    android:id="@+id/cnpj_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/cnpj"
    app:cnpjErrorMessage="@{@string/invalid_cnpj}"
    app:cnpjAutoDismiss="@{true}"
    app:cnpjRequired="@{true}" />
Kotlin Dsl:
  val cnpjField = findViewById(R.id.cnpj_field) as EditText
  val invalidCnpj = "Invalid cnpj"
  convalida {
    field(cnpjField) {
      isCnpj(errorMessage = invalidCnpj)
    }
  }
Isbn Validation
Isbn validation is applied to a field that will filled with a book number ID.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Isbn(
    errorMessageResId = R.string.invalid_isbn,
    autoDismiss = true,
    required = true
  )
  EditText isbnField;
Data Binding:
  <EditText
    android:id="@+id/isbn_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/isbn"
    app:isbnErrorMessage="@{@string/invalid_isbn}"
    app:isbnAutoDismiss="@{true}"
    app:isbnRequired="@{true}" />
Kotlin Dsl:
  val isbnField = findViewById(R.id.isbn_field) as EditText
  val invalidIsbn = "Invalid isbn"
  convalida {
    field(isbnField) {
      isIsbn(errorMessage = invalidIsbn)
    }
  }
Ipv4 Validation
Ipv4 validation is applied to a field that will filled with an Ipv4 address.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Ipv4(
    errorMessageResId = R.string.invalid_ipv4,
    autoDismiss = true,
    required = true
  )
  EditText ipv4Field;
Data Binding:
  <EditText
    android:id="@+id/ipv4_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/ipv4"
    app:ipv4ErrorMessage="@{@string/invalid_ipv4}"
    app:ipv4AutoDismiss="@{true}"
    app:ipv4Required="@{true}" />
Kotlin Dsl:
  val ipv4Field = findViewById(R.id.ipv4_field) as EditText
  val invalidIpv4 = "Invalid Ipv4"
  convalida {
    field(isbnField) {
      isIpv4(errorMessage = invalidIpv4)
    }
  }
Ipv6 Validation
Ipv6 validation is applied to a field that will filled with an Ipv6 address.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Ipv6(
    errorMessageResId = R.string.invalid_ipv6,
    autoDismiss = true,
    required = true
  )
  EditText ipv6Field;
Data Binding:
  <EditText
    android:id="@+id/ipv6_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/ipv6"
    app:ipv6ErrorMessage="@{@string/invalid_ipv6}"
    app:ipv6AutoDismiss="@{true}"
    app:ipv6Required="@{true}" />
Kotlin Dsl:
  val ipv6Field = findViewById(R.id.ipv6_field) as EditText
  val invalidIpv6 = "Invalid ipv6"
  convalida {
    field(ipv6Field) {
      isIpv6(errorMessage = invalidIpv6)
    }
  }
Url Validation
Url validation is applied to a field that will filled with an Url addres.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @Url(
    errorMessageResId = R.string.invalid_url,
    autoDismiss = true,
    required = true
  )
  EditText urlField;
Data Binding:
  <EditText
    android:id="@+id/url_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/url"
    app:urlErrorMessage="@{@string/invalid_url}"
    app:urlAutoDismiss="@{true}"
    app:urlRequired="@{true}" />
Kotlin Dsl:
  val urlField = findViewById(R.id.url_field) as EditText
  val invalidUrl = "Invalid url"
  convalida {
    field(urlField) {
      isUrl(errorMessage = invalidUrl)
    }
  }
Past Date Validation
Past Date validation is applied to a field that will filled with a date which cannot less than a past date limit.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
limitDate java.lang.String This parameter represents the past date limit.
dateFormat java.lang.String This parameter represents the format of date values to be passed.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @PastDate(
    dateFormat = US_DATE_FORMAT,
    limitDate = JAN_01_2000_DATE,
    errorMessageResId = R.string.invalid_past_date,
    autoDismiss = true,
    required = true
  )
  EditText pastDateField;
Data Binding:
  <EditText
    android:id="@+id/past_date_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/past_date"
    app:pastDateDateFormat="@{Patterns.US_DATE_FORMAT}"
    app:pastDateLimitDate="@{Constants.JAN_01_2000_DATE}"
    app:pastDateErrorMessage="@{@string/invalid_past_date}"
    app:pastDateAutoDismiss="@{true}"
    app:pastDateRequired="@{true}" />
Kotlin Dsl:
  val pastDateField = findViewById(R.id.past_date_field) as EditText
  val invalidPastDate = "Date exceeded the past date limit"
  convalida {
    field(pastDateField) {
      pastDate(
        dateFormat = US_DATE_FORMAT,
        limitDate = JAN_01_2000_DATE,
        errorMessage = invalidPastDate
      )
    }
  }
Future Date Validation
Future Date validation is applied to a field that will filled with a date which cannot greater than a future date limit.
Parameter Type Description
editText android.widget.EditText This parameter represents the field that will be validated.
limitDate java.lang.String This parameter represents the future date limit.
dateFormat java.lang.String This parameter represents the format of date values to be passed.
errorMessage java.lang.String This parameter represents the error message that will be displayed when field value is invalid.
autoDismiss boolean This parameter means the error message will disappear automatically when field value is valid.
required boolean This parameter means the field can accept an empty value or not.
Annotation:
  @FutureDate(
    dateFormat = US_DATE_FORMAT,
    limitDate = JAN_01_2010_DATE,
    errorMessageResId = R.string.invalid_future_date,
    autoDismiss = true,
    required = true
  )
  EditText futureDateField;
Data Binding:
  <EditText
    android:id="@+id/future_date_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/future_date"
    app:futureDateDateFormat="@{Patterns.US_DATE_FORMAT}"
    app:futureDateLimitDate="@{Constants.JAN_01_2010_DATE}"
    app:futureDateErrorMessage="@{@string/invalid_future_date}"
    app:futureDateAutoDismiss="@{true}"
    app:futureDateRequired="@{true}" />
Kotlin Dsl:
  val futureDateField = findViewById(R.id.future_date_field) as EditText
  val invalidFutureDate = "Date exceeded the future date limit"
  convalida {
    field(futureDateField) {
      futureDate(
        dateFormat = US_DATE_FORMAT,
        limitDate = JAN_01_2010_DATE,
        errorMessage = invalidFutureDate
      )
    }
  }