简体   繁体   中英

How to validate an email address using JavaScript?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM