question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not pass given value when validating email address

See original GitHub issue

Somewhat similar issue as #240, so I am keeping this short 😃

The documentation for the email-validator specifies the {1}-argument as the given value, but it is not interpolated into the message.

var validator = ValidatorBuilder.<String>of()
        .constraint((String email) -> email, "email",
                l -> l.email().message("{0} must be a valid email address, but was '{1}'"))
        .build();

var violation = validator.validate("@example.com").get(0);
assertThat(violation.message(), is("email must be a valid email address, but was '@example.com'"));
java.lang.AssertionError: 
Expected: is "email must be a valid email address, but was '@example.com'"
     but: was "email must be a valid email address, but was {1}"

Thought I’d also mention that the documentation for email-validator seems to be a little bit “off” as well, as it specifies the default message format as "{0}" must match {1}, but it does not make much sense to say "email" must match @example.com. However, the default message format seems to actually be "{0}" must be a valid email address, which is all fine, though it does not include the given value.

Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
makingcommented, May 6, 2022

MessageFormat is used to interpolate by default and the javadoc says

Within a String, a pair of single quotes can be used to quote any arbitrary characters except single quotes. For example, pattern string “‘{0}’” represents string “{0}”, not a FormatElement. A single quote itself must be represented by doubled single quotes ‘’ throughout a String.

Use "{0} must be a valid email address, but was ''{1}''" instead

0reactions
runeflobakkcommented, May 6, 2022

Oh… I was not aware of that gotcha with MessageFormat. Then it works as expected! Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

regex - How can I validate an email address using a regular ...
If you want to validate that an email is correct, you have no choice than to send a confirmation email and have the...
Read more >
4.1. Validate Email Addresses - Regular Expressions ...
The short answer to the validity problem is that you can't know whether john.doe@somewhere.com is an email address that can actually receive email...
Read more >
Check if email address valid or not in Python - GeeksforGeeks
Method 1: Check for a valid email address using regular expression. This method either returns None (if the pattern doesn't match) or re....
Read more >
<input type="email"> - HTML: HyperText Markup Language
The input will fail constraint validation if the length of the text value of the field is greater than maxlength UTF-16 code units...
Read more >
How to verify that strings are in valid email format
The example defines an IsValidEmail method, which returns true if the string contains a valid email address and false if it doesn't but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found