Email Validator accepts incomplete email address

Hello,

In testing an email validator’s functionality, I’ve simply added the following to a screen:

<row>
    <label value="Email"/>
    <textField id="emailField" required="true" requiredMessage="Email is required">
        <validators>
            <email message="Email not valid"/>
        </validators>
    </textField>
</row>

This allowed an email of ‘test@test’ to go through. I’ve verified this several times. Is this an error, or is there a reason for this?

Thanks in advance,
Adam

Hello, Adam!

EmailValidator uses hibernate email validation and it considers that ‘test@test’ is a valid value (see stackoverflow).

If you want more strict validation it is always possible to create your validator:

@Inject
private TextField<String> textField;
@Inject
private MessageBundle messageBundle;

@Subscribe
public void onInit(InitEvent event) {
    textField.addValidator(email -> {
        // your check here
        throw new ValidationException(messageBundle.getMessage("validation.email"));
    });
}
2 Likes

@Pinyazhin

Thanks for this information. I’ll create my own regex for it!