0

I'm using bootstrap validator but the email field accept "test@test". You can try it on my link. How can I do to fix that ? With the pattern attribute I can write a regex but I don't know do that.

I have already try this regex but all the emails are incorrect :

<?php 
    echo $this->tag->emailField(
        array(
            "email", 
            "class" => "form-control", 
            "data-error" => "incorrect address",
            "pattern" => '/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i',
            "required" => "required"
        )
    );
?>
yanckst
  • 438
  • 4
  • 17
John
  • 4,711
  • 9
  • 51
  • 101

2 Answers2

5

Why don't you simply set the type property of input tag to email and let HTML5 do the validation for you.

You can also add a pattern attribute to specify a regex. You can get a very popular regex from following link:

Validate email address in JavaScript?

pattern="^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$"
Community
  • 1
  • 1
adnan kamili
  • 8,967
  • 7
  • 65
  • 125
  • 1
    I use it but I want the bootstrap css dynamic with red / green color on the fields – John Aug 31 '15 at 09:52
  • The problem is the HTML5 validation. http://www.the-art-of-web.com/html/html5-form-validation/ there is the same bug. – John Aug 31 '15 at 10:42
  • 1
    @John why are you wasting time in trying to validate email with such high accuracy, when client side validation can easily be bypassed - simple validation client side - and serious validation server side; if some one types abs@abc.abc (which) is syntactically correct but in reality doesn't exist every client validation will pass it though invalid. – adnan kamili Aug 31 '15 at 10:46
  • This is just for the design. And I'm doing a validation server side too with Phalcon no problem. – John Aug 31 '15 at 10:51
  • Oh yes it works ! Thanks Thanks Thanks Thanks a lot ! You are awesome dude. – John Aug 31 '15 at 11:51
1

Ok I solved my problem with this regex.

pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"
John
  • 4,711
  • 9
  • 51
  • 101