Search code examples
htmlregexformsemail-validationhtml-input

Html5 pattern attribute not matching for email(user@gmail.com)


I am new to HTML5...

Here i am having some problem with email pattern attribute...

1)if i am giving the input like user@gmail.com... in email field..

2)it's not accepting value and showing "Pattern not matched"..

Help me to fix this....

Here is the snippet of Html

<form name='f1' method="POST" action=""  >     
  <div id="fp">


        <span style="margin-left:-50px">Email:</span>&nbsp;&nbsp;
        <span><input  class="input" type="email" name="Email" placeholder="Enter mailID" required pattern="^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$" ></span><br>


         <input type="submit"  name="submit" value="submit">

   </div>
  </form>    

Any suggestions are acceptable....


Solution

  • this should be correct pattern

    [^@]+@[^@]+\.[a-zA-Z]{2,6}
    

    yes you forgot to consider lower case.

    you can refer this document for more details

    html5-form-validation-with-regex