emailAddress validator

Validate an email address

Options

Using with form field

The HTML attributes are used to set the validator options via the Declarative plugin

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

Tip

This validator passes an empty field since the field might be optional. If the field is required, then use the notEmpty validator

You also can use the remote validator to connect and validate the email address on the server. The Mailgun plugin demonstrates how to do this.

Using with JavaScript module


// You might need to change the importing path
import emailAddress from 'formvalidation/validators/emailAddress';

const result = emailAddress().validate({
    value: ...,
    options: {
        message: ...,
        multiple: ...,
        separator: ...,
    },
});
/*
result is an object of
{
    valid: true or false,
    message: The error message
}
*/

Basic Example

You can click on sample to see if it's a valid or invalid email address.

Sample Is valid?
niceandsimple@example.com
very.common@example.com
a.little.lengthy.but.fine@dept.example.com
disposable.style.email.with+symbol@example.com
other.email-with-dash@example.com
"much.more unusual"@example.com
"very.unusual.@.unusual.com"@example.com
"very.(),:;<>[]".VERY."very@\ "very".unusual"@strange.example.com
admin@mailserver1
"!#$%&*+-/=?^_{}`|~@example.org"
" "@example.org
üñîçøðé@example.com
üñîçøðé@üñîçøðé.com
Abc.example.com
A@b@c@example.com
a"b(c)d,e:f;g<h>i[jk]l@example.com
just"not"right@example.com
this is"notallowed@example.com
this still"not\allowed@example.com

HTML5 Example

When the Declarative plugin is used, the emailAddress validator will be enabled automatically when using HTML5 type="email" attribute.

Is a@b valid email address?

Yes! It's valid email address. If you want to treat these kind of email addresses as invalid one, you can use the regexp validator to define expression of email address.

Module Example

The following snippet shows how to use the emailAddress validator with JavaScript module:


// You might need to change the importing path
import emailAddress from 'formvalidation/validators/emailAddress';

const res1 = emailAddress().validate({
    value: 'niceandsimple@example.com',
    options: {
        message: 'The value is not a valid email address',
    },
});
// res1.valid === true

const res2 = emailAddress().validate({
    value: 'just"not"right@example.com',
    options: {
        message: 'The value is not a valid email address',
    },
});
// res2.valid === false