code: public static boolean validateOptionalField(String field, String reg) {
          if (field == null || field.isEmpty()) {
              return true;
          }
          return Pattern.matches(reg, field);
      }
docs: Validate the optional field String against regex.
  
  @param field
  the field value String.
  @param reg
  the regex.
  @return true if field is empty of matched the pattern.