All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.univapay.sdk.models.common.EmailAddress Maven / Gradle / Ivy

There is a newer version: 0.2.35
Show newest version
package com.univapay.sdk.models.common;

import java.util.regex.Pattern;

public class EmailAddress implements UnivapayEmailAddress {

  private String email;

  private static final String ERROR_MESSAGE = "Must be a valid email address";
  private static final Pattern pattern =
      Pattern.compile(
          "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])");

  public EmailAddress(String email) {
    if (email == null) {
      throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    if (!email.toLowerCase().matches(pattern.pattern())) {
      throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    this.email = email;
  }

  @Override
  public String serialize() {
    return email;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy