Skip to content

Instantly share code, notes, and snippets.

@jaimedantas
Created March 31, 2021 23:38
Show Gist options
  • Save jaimedantas/4a18f97fae9d0706ad28e1fad63dd719 to your computer and use it in GitHub Desktop.
Save jaimedantas/4a18f97fae9d0706ad28e1fad63dd719 to your computer and use it in GitHub Desktop.
class ResourceValidator() : AbstractValidator<Resource>() {
val UUID_REGEX: String = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
override fun rules() {
ruleFor(Resource::id)
.must(stringMatches(UUID_REGEX))
.`when`(not(nullValue()))
.withMessage("The Resource Id is not valid")
.withFieldName("id")
.critical();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment