码迷,mamicode.com
首页 > 其他好文 > 详细

邮箱格式验证demo

时间:2016-07-11 14:13:51      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>
<script type="text/javascript">
    function validate_email(field, alerttxt) {
        with (field) {
            apos = value.indexOf("@")
            dotpos = value.lastIndexOf(".")
            if (apos < 1 || dotpos - apos < 2) {
                alert(alerttxt);
                return false 
            }
            else {
                return true 
            }
        }
    }

    function validate_form(thisform) {
        with (thisform) {
            if (validate_email(email, "Not a valid e-mail address!") == false) {
                email.focus();
                return false
             }
        }
    }
</script>
</head>

<body>
<form action="submitpage.htm"onsubmit="return validate_form(this);" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit"/> 
</form>
</body>
</html>

 

邮箱格式验证demo

标签:

原文地址:http://www.cnblogs.com/Teacher-chang/p/5659917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!