Documentation versions (currently viewingVaadin 14)
You are viewing documentation for an older Vaadin version. View latest documentation

Email Field

Email Field, an extension of Text Field, only accepts email addresses as input. If the given address is invalid, the field is highlighted in red and an error message appears underneath the input.

Open in a
new tab
EmailField validEmailField = new EmailField();
validEmailField.setLabel("Email address");
validEmailField.getElement().setAttribute("name", "email");
validEmailField.setErrorMessage("Please enter a valid email address");

EmailField invalidEmailField = new EmailField();
invalidEmailField.setLabel("Email address");
invalidEmailField.getElement().setAttribute("name", "email");
invalidEmailField.setValue("This is not an email");
invalidEmailField.setErrorMessage("Please enter a valid email address");

add(validEmailField, invalidEmailField);

Validity of the email addresses is checked according to the RFC 5322 standard, which includes the format for email addresses.

Common Input Field Features

Email Field includes all Text Field and shared input field features.

Pattern for Additional Validation

The pattern attribute is an additional validation criterion that you can set if, for example, a specific domain is required. The pattern is specified using regular expression.

The example below uses the pattern .+@example\.com and only accepts addresses in the domain.

Open in a
new tab
EmailField emailField = new EmailField();
emailField.setLabel("Email address");
emailField.getElement().setAttribute("name", "email");
emailField.setErrorMessage("Please enter a valid email address");