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.

EmailValidator doesn't pass on an empty string

See original GitHub issue

Vaadin 14.1.19. I have the following code:

binder.forField(new TextField()).withValidator(new EmailValidator()).bind("field");

However, the validator marks an empty TextField as invalid, effectively disabling the possibility to have an optional email.

Certainly I can hook a converter before the validator which converts empty string to null and vice versa (it’s required anyway because of TextField rejecting nulls), but I wonder whether EmailValidator should pass blank strings?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
denis-anisimovcommented, Jul 31, 2020

I suggest to overload EmailValidator CTOR with a boolean value which says whether an empty value should be accepted or not. That will keep binary compatibility and won’t require introducing a new class.

2reactions
Artur-commented, Apr 28, 2020
new EmailValidator() {
protected boolean isValid(String value) {
if ("".equals(value)) return true;
return super.isValid(value);
}
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Symfony 2 Email Validator Null Value - php - Stack Overflow
Look at the source of the validator: if an empty string or null is passed, it does nothing. In other words, empty values...
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 >
Built-in Validators — FluentValidation documentation
NotEmpty Validator¶. Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, e.g.,...
Read more >
Testing Exceptions in PHPUnit - BackEndTea
We use the EmailValidator to make sure that the emails are only from our company. //Email.php final class Email { private function __ ......
Read more >
Java email regex examples - Mkyong.com
isValid(email)); } // Valid email addresses static Stream<String> ... EmailValidator; public class EmailValidatorApache { //doesn't consider ...
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