in domain/src/main/java/demoapp/dom/progmodel/customvaluetypes/customvalues/EmailAddressValueSemantics.java [98:127]
public Parser<EmailAddress> getParser() {
return new Parser<>() {
// https://stackoverflow.com/a/47181151
final Pattern REGEX = Pattern.compile("^[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-zA-Z]{2,})$");
@Override
public String parseableTextRepresentation(Context context, EmailAddress value) {
return renderTitle(value, EmailAddress::getEmailAddress);
}
@Override
public EmailAddress parseTextRepresentation(Context context, String text) {
if(!REGEX.matcher(text).matches()) {
throw new RuntimeException("Invalid email format");
}
if (_Strings.isEmpty(text)) return null;
return EmailAddress.of(text);
}
@Override
public int typicalLength() {
return 20;
}
@Override
public int maxLength() {
return 50;
}
};
}