-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zdeněk Balák
committed
Jun 25, 2020
1 parent
def2116
commit d54a970
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...rary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NullableEmailValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |