Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.67 KB

email.md

File metadata and controls

28 lines (19 loc) · 1.67 KB

Email Fields

If you need to collect emails then that will automatically be handled for you with a HTML5 <input type="email"> field if you annotate your model field correctly:

[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[EmailAddress]
public string Email { get; set; }

Validation

If you just apply the [DataType] attribute it won't perform any server-side validation, but it will apply client-side validation attributes. If you apply the [EmailAddress] attribute it will also perform basic server-side validation. Fun-fact: the server-side validation used to be more comprehensive, but was simplified due to a security vulnerability. At the end of the day, the best way to verify an email address (if you really need to) is to send an email to it.

Default HTML

When using the Default Field Generator then the default HTML of the Field Element will be:

<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" type="email" value="%value%" />

If the field is required then the default HTML will be:

<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" required="required" type="email" value="%value%" />