Validate Email Addresses in Forms.

No more wonky data.

DEMO #1

This form uses the browser's default validation only.

The input field is set to required, with type=email.

Notes

Emails like foo@bar will be accepted.

Try a few emails to see the errors it displays and the emails that will be accepted.

When the form would have submitted, you'll see a pop-up alert.

Give it a try >>>

Default email validation

Try it! If the form would have validated, you'll see a pop-up alert message.
Thank you! You've been added to our amazing mailing list!
Oops! Something went wrong while submitting the form.

DEMO #2

Here we use the same default settings on the INPUT element, but we add a custom pattern attribute.

See the pattern here.

Notes

Patterns allow us to specify the exact regex pattern we want the browser to require for validation.

Validation applies in layers.

Try different entries and notice the different errors you see when you enter, e.g.;

  • an empty string
  • bob
  • bob@foo

Give it a try >>>

Pattern-based email validation

Try it! If the form would have validated, you'll see a pop-up alert message.
Thank you! You've been added to our amazing mailing list!
Oops! Something went wrong while submitting the form.

DEMO #3

Some browsers allow us to improve the messaging when the pattern validation fails.

Here we've added a custom title attribute to the email field.

Notes

The title should not assume that an error has occurred. It should indicate what the field expects.

Give it a try >>>

Pattern-based email validation w/ Title

Try it! If the form would have validated, you'll see a pop-up alert message.
Thank you! You've been added to our amazing mailing list!
Oops! Something went wrong while submitting the form.

See the code.

See the Pen Webflow | Forms | Email Validation by Michael Wells (@memetican) on CodePen.