title: How to validate whethere a username is an email or phone number in springboot application
body: <p>I am quite new to springboot and I am trying to create validate whether a username field is a phone number or email address in my registerDTO.</p>
  <p>Here is how the registerDTO looks like:</p>
  <p>import lombok.Data;
  import lombok.Data;</p>
  <pre><code>import javax.validation.constraints.*;
  
  @Data
  public class RegisterDTO {
      @NotNull(message= &quot;This field cannot be blank&quot;)
      private String firstName;
      @NotNull(message=&quot;This field cannot be blank&quot;)
      private String lastName;
      private String username;
  
      @Digits(integer = 4, fraction = 0)
      @Pattern(regexp =&quot;^[0-9]{4}$&quot;)
      @Size(min=4, max=4, message = &quot;Password can only be 4 digits&quot;)
      private Integer password;
  </code></pre>
  <p>I want to write a custom regex that will validate if the username instance is either an email or phone number. The phone number should start with zero and not exceed 11 (maximum_length). It should throw an error if it's neither of the two.</p>