Skip to content

Instantly share code, notes, and snippets.

@mchmielarz
Created December 17, 2018 22:11
Show Gist options
  • Save mchmielarz/c08501f3996037e2888d44b0be725292 to your computer and use it in GitHub Desktop.
Save mchmielarz/c08501f3996037e2888d44b0be725292 to your computer and use it in GitHub Desktop.
IbanValidator class
@Slf4j
public class IbanValidator implements ConstraintValidator<Iban, String> {
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
  if (value == null) {
  return false;
}
return Try.of(() -> {
if (value.contains(" ")) {
IbanUtil.validate(value, IbanFormat.Default);
} else {
IbanUtil.validate(value);
}
return true;
})
.onFailure(exc -> log.error("Invalid IBAN provided: {}", value, exc))
  .getOrElseGet(exc -> false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment