-2

my code is below both are in diffrent pages

<tr>
  <td width="100">email:</td><td width="100"><input type="email" name="mailid" id="mail" onKeyUp="validateemail()" required></td><td><label id="vem"></label></td>
</tr>

JS

function validateemail() {
    var chmail=document.getElementById("mail");
    if(chmail.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/))
    {
        producePrompt("valid email","vem","green"); 
        return false;

    }

    producePrompt("email invalid","vem","red"); 
        return true;


}
zoranc
  • 2,410
  • 1
  • 21
  • 34
user3417046
  • 11
  • 2
  • 6
  • 1
    Don't reinvent e-mail regexes...http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address – loveNoHate Mar 13 '14 at 19:36
  • This question isn't a duplicate of the question against which it is marked as duplicate. That question blindly asks how to do something. The OP is asking what is wrong with his code. I'm not at all saying this is a good question, but closing questions with incorrect reason is a bad idea - atleast it should be closed with a proper reason... Hence voting to re-open. – T J Oct 19 '14 at 15:19

1 Answers1

0
var chmail=document.getElementById("mail"); //returns the input element.

replace it with

var chmail=document.getElementById("mail").value; // returns the value

FIDDLE

side note: hopefully producePrompt() is defined somewhere in your code..

T J
  • 42,762
  • 13
  • 83
  • 138