com.vaadin.flow.component.textfield.

Class EmailField

All Implemented Interfaces:

AttachNotifier, BlurNotifier<EmailField>, CompositionNotifier, DetachNotifier, Focusable<EmailField>, FocusNotifier<EmailField>, HasAriaLabel, HasElement, HasEnabled, HasHelper, HasLabel, HasPlaceholder, HasSize, HasStyle, HasTheme, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>, InputNotifier, KeyNotifier, HasAllowedCharPattern, HasClearButton, HasClientValidation, HasPrefix, HasSuffix, HasThemeVariant<TextFieldVariant>, HasTooltip, HasValidationProperties, InputField<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>, HasAutocapitalize, HasAutocomplete, HasAutocorrect, HasPrefixAndSuffix, HasValidator<String>, HasValueChangeMode, Serializable

@Tag("vaadin-email-field") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.0-alpha7") @NpmPackage(value="@vaadin/email-field",version="24.7.0-alpha7") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/email-field/src/vaadin-email-field.js") public class EmailField extends TextFieldBase<EmailField,String> implements HasAllowedCharPattern, HasThemeVariant<TextFieldVariant>

Email Field is an extension of Text Field that only accepts email addresses as input.

Validation

Email Field comes with a built-in validation mechanism based on constraints. Validation is triggered whenever the user applies an input change, for example by pressing Enter or blurring the field. Programmatic value changes trigger validation as well. In eager and lazy value change modes, validation is also triggered on every character press with a delay according to the selected mode.

Validation verifies that the address adheres to the RFC 5322 standard email format and satisfies the specified constraints. If validation fails, the component is marked as invalid and an error message is displayed below the input.

The following constraints are supported:

setPattern(String) can be used to modify the default email format, for example, to require a specific email domain.

Error messages for email format and constraints can be configured with the EmailField.EmailFieldI18n object, using the respective properties. If you want to provide a single catch-all error message, you can also use the setErrorMessage(String) method. Note that such an error message will take priority over i18n error messages if both are set.

In addition to validation, constraints may also limit user input. For example, the browser will prevent the user from entering more text than specified by the maximum length constraint.

For more advanced validation that requires custom rules, you can use Binder. By default, before running custom validators, Binder will also check the component constraints and display error messages from the EmailField.EmailFieldI18n object. The exception is the required constraint, for which Binder provides its own API, see asRequired().

However, if Binder doesn't fit your needs and you want to implement fully custom validation logic, you can disable the constraint validation by setting setManualValidation(boolean) to true. This will allow you to control the invalid state and the error message manually using HasValidationProperties.setInvalid(boolean) and setErrorMessage(String) API.

Author:

Vaadin Ltd.

See Also: