本文主要是介绍html5 JavaScript 邮箱地址验证,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!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>
http://www.ihref.com/read-7684.html
这篇关于html5 JavaScript 邮箱地址验证的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!