HTML5 Email Validation


Html Problem Overview

It is said "With HTML5, we need no more js or a server side code to check if the user's input is a valid email or url address"

How can I validate email after a user enter? and without JS how to display a message if the user enter a wrong form of his/her email address.

<input type="email" pattern="[^ @]*@[^ @]*" placeholder="Enter your email">
<input type="submit" value="Submit">

Html Solutions

Solution 1 - Html

In HTML5 you can do like this:

<input type="email" placeholder="Enter your email">
<input type="submit" value="Submit">

And when the user press submit, it automatically shows an error message like:

Error Message

Solution 2 - Html

The input type=email page of the site notes that an email address is any string which matches the following regular expression:


Use the required attribute and a pattern attribute to require the value to match the regex pattern.


Solution 3 - Html

Using [a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,} for [email protected] / [email protected]

Solution 4 - Html


seems to be true when field is either empty or valid. This also has some other interesting flags:

enter image description here

Tested in Chrome.

Solution 5 - Html

I know you are not after the Javascript solution however there are some things such as the customized validation message that, from my experience, can only be done using JS.

Also, by using JS, you can dynamically add the validation to all input fields of type email within your site instead of having to modify every single input field.

var validations ={
    email: [/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/, 'Please enter a valid email address']
    // Check all the input fields of type email. This function will handle all the email addresses validations
    $("input[type=email]").change( function(){
        // Set the regular expression to validate the email 
        validation = new RegExp(validations['email'][0]);
        // validate the email value against the regular expression
        if (!validation.test(this.value)){
            // If the validation fails then we show the custom error message
            return false;
        } else {
            // This is really important. If the validation is successful you need to reset the custom error message

Solution 6 - Html

Here is the example I use for all of my form email inputs. This example is ASP.NET, but applies to any:

<asp:TextBox runat="server" class="form-control" placeholder="Contact's email" 
    name="contact_email" ID="contact_email" title="Contact's email (format: [email protected])" 
    type="email" TextMode="Email" validate="required:true"
    pattern="[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*" >

HTML5 still validates using the pattern when not required. Haven't found one yet that was a false positive.

This renders as the following HTML:

<input class="form-control" placeholder="Contact's email" 
    name="contact_email" id="contact_email" type="email" 
    title="Contact's email (format: [email protected])" 

Solution 7 - Html

A bit late for the party, but this regular expression helped me to validate email type input in the client side. Though, we should always do verification in server side also.

<input type="email" pattern="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$">

You can find more regex of all kinds here.

Solution 8 - Html

TL;DR: The only 100% correct method is to check for @-sign somewhere in the entered email address and then posting a validation message to given email address. If they can follow validation instructions in the email message, the inputted email address is correct.

Long answer:

David Gilbertson wrote about this years ago: > There are two questions we need to ask: > > 1. Did the user understand that they were supposed to type an email > address into this field? > 2. Did the user correctly type their own email > address into this field? > > If you have a well laid-out form with a label > that says “email”, and the user enters an ‘@’ symbol somewhere, then > it’s safe to say they understood that they were supposed to be > entering an email address. Easy. > > Next, we want to do some validation to ascertain if they correctly > entered their email address. > > Not possible. > > [...] > > Any mistype will definitely result in an incorrect email address, but only maybe result in an invalid email address. > > [...] > > There is no point in trying to work out if an email address is ‘valid’. A user is far more likely to enter a wrong and valid email address than they are to enter an invalid one.

In other words, it's important to notice that any kind of string based validation can only check if the syntax is invalid. It cannot check if the user can actually see the email (e.g. because the user already lost credentials, typed address of somebody else or typed work email instead of personal email address for a given use case). How often the question you're really after is "is this email syntactically valid" instead of "can I communicate with the user using given email address"? If you validate the string more than "does it contain @", you're trying to answer the former question! Personally, I'm always interested about the latter question only.

In addition, some email addresses that may be syntactically or politically invalid, do work. For example, postmaster@ai does technically work even though TLDs should not have MX records. Also see discussion about email validation on the WHATWG mailing list (where HTML5 is designed in the first place).

Solution 9 - Html

You can follow this pattern also

<form action="/action_page.php">
  E-mail: <input type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
  <input type="submit">

Ref : In W3Schools

Solution 10 - Html

Using HTML 5,Just make the input email like :

<input type="email"/>

When the user hovers over the input box, they will a tooltip instructing them to enter a valid email. However, Bootstrap forms have a much better Tooltip message to tell the user to enter an email address and it pops up the moment the value entered does not match a valid email.

Solution 11 - Html

According to MDN, this RegExp is ok to validate emails, as emails that meet specifications should match it.


Solution 12 - Html

It is very difficult to validate Email correctly simply using HTML5 attribute "pattern". If you do not use a "pattern" someone@ will be processed. which is NOT valid email.

Using pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}" will require the format to be [email protected] however if the sender has a format like [email protected] (or similar) will not be validated to fix this you could put pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}" this will validate " or or alike.

However using this, it will not permit [email protected] to validate. So as far as simply using HTML5 to validate email addresses is still not totally with us. To Complete this you would use something like this:

<input id="email" type="text" name="email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}" required placeholder="Enter you Email">
<input type="submit" value="Submit The Form">


<input id="email" type="text" name="email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,}" required placeholder="Enter you Email">
<input type="submit" value="Submit The Form">

However, I do not know how to validate both or all versions of email addresses using HTML5 pattern attribute.

Solution 13 - Html

If you just learning HTML and you want a simple solution this code will do the job for you

    <input type="email" placeholder="Enter your email">
    <input type="submit" value="Submit" required>

But if you are a professional and want something secure and keep your database clean there is a paid service called DeBounce API it validates the email on the frontend that way you don't get an invalid email in your data it works like this,

if an invalid email is provided, the email address will be converted to a placeholder (which is equal to an empty input), so if the email field is a mandatory one, the form cannot submit here is there website


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionabcid dView Question on Stackoverflow
Solution 1 - HtmlMidhun MPView Answer on Stackoverflow
Solution 2 - HtmlStefan Ciprian HotoleanuView Answer on Stackoverflow
Solution 3 - HtmlVan NguyenView Answer on Stackoverflow
Solution 4 - HtmlNakilonView Answer on Stackoverflow
Solution 5 - Htmlkaric83View Answer on Stackoverflow
Solution 6 - HtmlKeith H.View Answer on Stackoverflow
Solution 7 - HtmlNBSamarView Answer on Stackoverflow
Solution 8 - HtmlMikko RantalainenView Answer on Stackoverflow
Solution 9 - HtmlskpaikView Answer on Stackoverflow
Solution 10 - HtmlFabian MaduraiView Answer on Stackoverflow
Solution 11 - HtmlZachT112View Answer on Stackoverflow
Solution 12 - HtmlKeithView Answer on Stackoverflow
Solution 13 - HtmlKasem777View Answer on Stackoverflow