-1

I'm using the pattern:

var pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

So when I submit/send an email to myself from my contact form to test out a bunch of different email combinations, everything has worked except for:

whatever@yahoo.com && whatever@google.com

I'm not entirely sure why those two aren't being included, but I'd appreciate any assistance.

user5680735
  • 703
  • 2
  • 7
  • 21
Speakmore
  • 69
  • 2
  • 11

3 Answers3

0

I'm not sure whats going wrong with yours, but here's an email pattern I've used successfully.

pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"
user4740600
  • 79
  • 1
  • 8
0

This help you :

 var patt = /^[A-Za-z0-9]+@[A-Za-z0-9]+\.[A-Za-z]+$/gmi

final code :

<html>
<head>
</head>
    <body>
        Enter Your Email : <input type="tel" id="email">
        <button onclick="isvalid()">Try</button>
        <p id="res"></p>
      <script>
          var res = document.getElementById("res");
          var patt = /^[A-Za-z0-9]+@[A-Za-z0-9]+\.[A-Za-z]+$/gmi
          function isvalid(){
              str = document.getElementById("email").value;
              if(patt.test(str))
                  res.innerHTML = "Email is Valid";
              else
                  res.innerHTML = "Email is InValid";
          }
      </script>
    </body>
</html>
Ehsan
  • 12,655
  • 3
  • 25
  • 44
  • I didn't receive an email from test@yahoo.com nor test@google.com when usingthis – Speakmore Jun 22 '16 at 21:00
  • @Speakmore The test() method tests for a match in a string. This method returns true if it finds a match, otherwise it returns false. – Ehsan Jun 22 '16 at 21:06
  • if find whatever@yahoo.com return True else return false.you can try another email. – Ehsan Jun 22 '16 at 21:09
  • So this is what I currently have: 'function isValidEmail(emailAddress) { var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"; return pattern.test(emailAddress); };' – Speakmore Jun 22 '16 at 21:18
  • @Speakmore i updated my post. – Ehsan Jun 22 '16 at 21:26
0

I guess you miss some chars in your pattern, you may find here an answer

Validate email address in JavaScript?

there is a code which handles more chars that you forgot, and the comment above too.

Community
  • 1
  • 1
Ami Hollander
  • 2,435
  • 3
  • 29
  • 47