0

i am trying to doing input validation its my complete code but it is not working well.

<html>

<head>

<title>Testing Validation</title>
<script type = "text/javascript">
function getvalue()
{
    value = document.getElementById('myId').value;
    if(value < 'a' || value > 'z' || value != '@' && value != '.')
    {

        alert("Not a valid E-mail adress");
    }
}

</script>
</head>

<body>
<form name = "frm">
<input type="text" name="input" size="40" id="myId" />
<input type = "submit" name = "submit" onclick="getvalue()" />
</form>
</body>

</html>
2

1 Answer 1

2

If you want to check that an email is valid, look for solutions using regex. This has been discussed before on SO: Using a regular expression to validate an email address

12
  • 1
    There exist email addresses with non-latin characters and it will be more in near future. There are also tld's with more than 4 chars (e.g. .museum). See this answer for another regex example.
    – BalusC
    Commented Jun 24, 2010 at 14:48
  • It still assumes a limit on the length of the TLD, so it isn't future proof. Oh, and it rejects email addresses with plus characters in them (as well as the aforementioned problem about non-latin characters).
    – Quentin
    Commented Jun 24, 2010 at 15:16
  • @david: I'm not trying to get the optimal solution, just something that'll help imran while keeping it simple ^^
    – marcgg
    Commented Jun 24, 2010 at 16:02
  • Rejecting perfectly good email addresses is somewhat worse then "suboptimal". There are too many broken regular expressions purporting to validate email addresses resulting in people being unable to sign up to websites they want to use, frustrating end users and losing companies business. We don't need any more of this junk being published, and where it is published, it needs warnings wrapped around it so, hopefully, nobody will be foolish enough to actually try to use it. You said you are trying to keep it simple, but you aren't keeping it simple enough, you are being too specific throughout
    – Quentin
    Commented Jun 24, 2010 at 16:24
  • @david dorward: I've edited my answer. My main point was "do not make a loop, use a regex", I didn't pay attention to the actual regex I gave (first google result). What you're saying makes sense, hence the update.
    – marcgg
    Commented Jun 24, 2010 at 16:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.