Skip to content

Commit

Permalink
FEAT: NullableEmailValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
Zdeněk Balák committed Jun 25, 2020
1 parent def2116 commit d54a970
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion formbuilderlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "7.4"
versionName "7.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cz.qase.android.formbuilderlibrary.validator

import android.util.Patterns
import cz.qase.android.formbuilderlibrary.ValidationException

/**
* Field validator
*
* Is ok when value is not null and not blank (aka empty or made only of whitespaces)
* see String.isNullOrBlank()
*/
class NullableEmailValidator(private val errorMsg: String) : FormValidator<String> {
override fun validate(value: String?) {
if (!value.isNullOrBlank()) {
if (!Patterns.EMAIL_ADDRESS.matcher(value).matches()) {
throw ValidationException(errorMsg)
}
}
}
}

0 comments on commit d54a970

Please sign in to comment.