百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>html5教程> html5 JavaScript 邮箱地址验证
分享文章到:

html5 JavaScript 邮箱地址验证

发布时间:01/15 来源: 浏览: 关键词:

<!doctype html>
<html lang="en">
<head>
<meta charset=utf-8 />
<title>html5 网页特效 邮箱地址验证</title>
<style>
body, input, textarea {
  font-family: "helvetica", arial, helvetica;
}
label {
  display: block;
  float: left;
  clear: left;
  text-align: right;
  width: 100px;
  margin-right: 10px;
}

div { padding: 10px; }

fieldset { border: 1px solid #ccc; margin-bottom: 20px; }

</style>
</head>
<body>
<form>
  <fieldset>
    <legend>some bits about you</legend>
    <div><label for="email">email:</label> <input id="email" name="email" type="email" /></div>

    <div><label for="url">homepage:</label><input id="url" type="url" name="url" required /></div>
    <div><textarea name="comment" cols="100" rows="5" required></textarea></div>
  </fieldset>
  <input type="submit" />
</form>
<script>
// default validation messages
var messages = {
  email: 'be not a legal email address',
  url: 'be not a valid web address',
  comment: 'ye have to specify ye value'
};
var forms = document.getelementsbytagname('form'), i = forms.length, j, el;
while (i--) {
  j = forms[i].length;
  while (j--, el = forms[i][j]) {
    if (el.willvalidate && messages[el.name]) {
      el.setcustomvalidity(messages[el.name]);
    }
  }
}
</script>
<script>
var form = document.getelementsbytagname('form')[0];
form.onsubmit = function (event) {
  var i = this.length, el, cont = true, errors = [];
  while (i--, el = this[i]) {
    if (el.willvalidate) {
      if (!el.validity.valid) {
        errors.push('error with ' + el.name + (el.validationmessage ? ': ' + el.validationmessage: ''));
        cont = false;
      }
    }
  }
 
  if (errors.length) {
    // replace alert with your sexy css教程 info bubbles
    alert(errors.join('n'));
  }

  return cont;
};
</script>
</body>
</html>

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有13人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板