Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html5 pattern attribute not matching for email([email protected])

I am new to HTML5...

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

1)if i am giving the input like [email protected]... 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....

like image 580
PHP CODER Avatar asked Jul 04 '13 07:07

PHP CODER


4 Answers

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

like image 66
Ashish Chopra Avatar answered Sep 21 '22 14:09

Ashish Chopra


The accepted answer won't validate [email protected] In this case not to miss out all those new domain names emails like http://www.iflove.technology/ you could use:

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

Used with input type email it looks like this:

<input type="email" pattern="[^@]+@[^@]+\.[a-zA-Z]{2,}">
like image 27
Marian Zburlea Avatar answered Sep 19 '22 14:09

Marian Zburlea


You need to account for lower cases too. Or make it case insensitive. But in reality you should just use:

^.+@.+$

And send a confirmation e-mail to the address that they should follow because e-mail addresses are reasonably complicated and you'll end up blocking stuff you don't intend to with a regex and it doesn't stop someone putting in a fake e-mail address anyway.

like image 38
ydaetskcoR Avatar answered Sep 22 '22 14:09

ydaetskcoR


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]

like image 43
sambatha Avatar answered Sep 22 '22 14:09

sambatha