Created
December 17, 2018 22:11
-
-
Save mchmielarz/c08501f3996037e2888d44b0be725292 to your computer and use it in GitHub Desktop.
IbanValidator class
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
@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