emailAddress validator
Validate an email address
Options
Using with form field
Name | HTML attribute | Type | Description |
---|
message | data-fv-email-address___message | String | The error message |
multiple | data-fv-email-address___multiple | String | Allow multiple email addresses, separated by a comma or semicolon. The default value is false |
separator | data-fv-email-address___separator | String | Regex for character or characters expected as separator between addresses. By default, it is /[,;]/, i.e. comma or semicolon |
This validator passes an empty field since the field might be optional. If the field is required, then use the
notEmpty validatorYou also can use the
remote validator to connect and validate the email address on the server. For example, the
Mailgun plugin demonstrates how to do this.
Using with ES6 module
import emailAddress from 'formvalidation/dist/es6/validators/emailAddress';
const result = emailAddress().validate({
value: ...,
options: {
message: ...,
multiple: ...,
separator: ...,
},
});
Basic example
HTML5 Example
When the
Declarative plugin is used, the emailAddress validator will be enabled automatically when using HTML5
type="email"
attribute.
ES6 Module Example
The following snippet shows how to use the emailAddress validator with ES6 module:
import emailAddress from 'formvalidation/dist/es6/validators/emailAddress';
const res1 = emailAddress().validate({
value: 'niceandsimple@example.com',
options: {
message: 'The value is not a valid email address',
},
});
const res2 = emailAddress().validate({
value: 'just"not"right@example.com',
options: {
message: 'The value is not a valid email address',
},
});
See also
Changelog
- Fix a bug that emailAddress validator doesn't support multiple email addresses on IE 11