In a system, I'm working in, the username must be either email or cell number.
I'm using Hibernate Validator to validate the bean.
I want to create a custom annotation @Username such that it validate a bean property to be either email or a cell number.
Email can be validated with @Email and cell number with a regex using @Pattern but I couldn't figure out how to write a custom validator such that I can reuse above built-in annotations.
I referred to Creating custom validator section to create custom validator.
Basically my question is,
How can I use built-in validation annotations (@Email and @Pattern) to compose a new annotation @Username such that @Username validate a property to be either email or cell number?
// @Email or @Pattern("...") ???
@Target(FIELD)
@Retention(RUNTIME)
@Constraint(validatedBy = {})
@Documented
public @interface Username {
/* ... */
}