html事例
2015-08-23 22:30
519 查看
function checkName()
{
var username = document.getElementById("username").value;
//var username = document.getElementsByName("username")[0].value;
//alert(username);
//alert(name);
if(username=="")
{
alert("用户名不能为空");
return false;
}
for(var i=0;i<username.length;i++)
{
var ch=username.charAt(i);
if((ch<'0'||ch>'9')&&(ch<'a'||ch>'z')&&(ch<'A'||ch>'Z')&&ch!='_')
{
//alert("用户名只能是数字、字母、下划线组成");
var divElement=document.getElementById("uname");
divElement.innerHTML="<font color='red'>√</font>";
return false;
}
}
return true;
}
function check()
{
return checkName();
}
function checkWord()
{
var password = document.getElementById("password").value;
var len=password.length;
if(password==""||password==null)
{
alert("密码不能为空");
return false;
}
for(var j=0;j<password.length;j++)
{
var code=password.charCodeAt(j);
if(code>53)
{
len++;
}
}
if(len>6)
{
var divElement=document.getElementById("pword");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("密码输入不正确");
return false;
}
}
function check()
{
return checkWord();
}
function checkWords()
{
// checkWord();
var password= document.getElementById("password").value;
var passwords = document.getElementById("passwords").value;
// var len=passwords.length;
if(passwords==""||passwords==null)
{
alert("确认密码不能为空");
return false;
}
if(passwords.length<6)
{
alert("密码不能少于6位");
return false;
}
if(passwords==password)
{
var divElement=document.getElementById("pwords");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("密码输入不正确");
return false;
}
}
function check()
{
return checkWords();
}
function checkPhone()
{
var phone= document.getElementById("phone").value;
var len=phone.length;
if(phone==""||phone==null)
{
alert("电话号码不能为空");
return false;
}
for(var j=0;j<phone.length;j++)
{
var code=phone.charCodeAt(j);
if(code>59)
{
len++;
}
}
if(len==11)
{
var divElement=document.getElementById("ph");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("电话号码输入不正确");
return false;
}
}
function check()
{
return checkPhone();
}
function checkEmail()
{ var email = document.getElementById("email").value;
if(email==""&&email==null)
{
alert("邮箱不能为空");
return false;
}
else
{
reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
//return true;
if(!reg.test(email))
{
alert("非法的电子邮箱");
return false;
}
else
{
var divElement=document.getElementById("em");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
}
}
function checkqqNum()
{
var qqnum = document.getElementById("qqnum").value;
//var username = document.getElementsByName("username")[0].value;
//alert(qqnum);
//alert(name);
if(qqnum=="")
{
alert("qq号码不能为空");
return false;
}
for(var i=0;i<qqnum.length;i++)
{
var ch=qqnum.charAt(i);
if(ch>'0'&&ch<'9')
{
//alert("用户名只能是数字、字母、下划线组成");
var divElement=document.getElementById("qq");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
}
}
function check()
{
return checkqqNum();
}
-----------------------------------------------------------
<html>
<head>
<title>注册页面</title>
<!--设置浏览器的编码方式-->
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!--在其他所有内容之前装载此脚本-->
<script type="text/javascript"
src="regist.js">
</script>
</head>
<body>
<center>
<h1>注册</h1>
<form action="index.html" method="get" onsubmit="return check() " ;">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name ="username" id="username" onblur="checkName()"/></td>
<td>
<div id="uname">* 用户名只能是数字、字母、下划线组成
</div>
</td>
</tr>
<tr>
<td>初始密码:</td>
<td><input type="text" name ="password" id="password" onblur="checkWord()"/></td>
<td><div id="pword">* 密码至少为6位</div></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="text" name ="passwords" id="passwords" onblur="checkWords()"/></td>
<td><div id="pwords">* 必须和初始密码保持一致<div></td>
</tr>
<tr>
<td>电话号码:</td>
<td><input type="text" name ="phone" id="phone" onblur="checkPhone()"/></td>
<td><div id="ph">* 只能输入11位数字!例:13595144582或08514785214</div></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name ="email" id="email" value="@" onclick="checkEmail()"/></td>
<td><div id="em">* E-mail格式不正确!例:jiie@163.com</div></td>
</tr>
<tr>
<td>QQ号码:</td>
<td><input type="text" name ="qqNum" id="qqNum" onblur="checkqqNum()"/></td>
<td><div id="qq">QQ号码只能输入数字</div></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交" />
<input type="reset" value="重置"/>
</td>
<td></td>
</tr>
<tr>
<td>
<font color="red">*为必填项</font>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
用HTML和jsp来实现一个注册页面
{
var username = document.getElementById("username").value;
//var username = document.getElementsByName("username")[0].value;
//alert(username);
//alert(name);
if(username=="")
{
alert("用户名不能为空");
return false;
}
for(var i=0;i<username.length;i++)
{
var ch=username.charAt(i);
if((ch<'0'||ch>'9')&&(ch<'a'||ch>'z')&&(ch<'A'||ch>'Z')&&ch!='_')
{
//alert("用户名只能是数字、字母、下划线组成");
var divElement=document.getElementById("uname");
divElement.innerHTML="<font color='red'>√</font>";
return false;
}
}
return true;
}
function check()
{
return checkName();
}
function checkWord()
{
var password = document.getElementById("password").value;
var len=password.length;
if(password==""||password==null)
{
alert("密码不能为空");
return false;
}
for(var j=0;j<password.length;j++)
{
var code=password.charCodeAt(j);
if(code>53)
{
len++;
}
}
if(len>6)
{
var divElement=document.getElementById("pword");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("密码输入不正确");
return false;
}
}
function check()
{
return checkWord();
}
function checkWords()
{
// checkWord();
var password= document.getElementById("password").value;
var passwords = document.getElementById("passwords").value;
// var len=passwords.length;
if(passwords==""||passwords==null)
{
alert("确认密码不能为空");
return false;
}
if(passwords.length<6)
{
alert("密码不能少于6位");
return false;
}
if(passwords==password)
{
var divElement=document.getElementById("pwords");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("密码输入不正确");
return false;
}
}
function check()
{
return checkWords();
}
function checkPhone()
{
var phone= document.getElementById("phone").value;
var len=phone.length;
if(phone==""||phone==null)
{
alert("电话号码不能为空");
return false;
}
for(var j=0;j<phone.length;j++)
{
var code=phone.charCodeAt(j);
if(code>59)
{
len++;
}
}
if(len==11)
{
var divElement=document.getElementById("ph");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
else
{
alert("电话号码输入不正确");
return false;
}
}
function check()
{
return checkPhone();
}
function checkEmail()
{ var email = document.getElementById("email").value;
if(email==""&&email==null)
{
alert("邮箱不能为空");
return false;
}
else
{
reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
//return true;
if(!reg.test(email))
{
alert("非法的电子邮箱");
return false;
}
else
{
var divElement=document.getElementById("em");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
}
}
function checkqqNum()
{
var qqnum = document.getElementById("qqnum").value;
//var username = document.getElementsByName("username")[0].value;
//alert(qqnum);
//alert(name);
if(qqnum=="")
{
alert("qq号码不能为空");
return false;
}
for(var i=0;i<qqnum.length;i++)
{
var ch=qqnum.charAt(i);
if(ch>'0'&&ch<'9')
{
//alert("用户名只能是数字、字母、下划线组成");
var divElement=document.getElementById("qq");
divElement.innerHTML="<font color='red'>√</font>";
return true;
}
}
}
function check()
{
return checkqqNum();
}
-----------------------------------------------------------
<html>
<head>
<title>注册页面</title>
<!--设置浏览器的编码方式-->
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!--在其他所有内容之前装载此脚本-->
<script type="text/javascript"
src="regist.js">
</script>
</head>
<body>
<center>
<h1>注册</h1>
<form action="index.html" method="get" onsubmit="return check() " ;">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name ="username" id="username" onblur="checkName()"/></td>
<td>
<div id="uname">* 用户名只能是数字、字母、下划线组成
</div>
</td>
</tr>
<tr>
<td>初始密码:</td>
<td><input type="text" name ="password" id="password" onblur="checkWord()"/></td>
<td><div id="pword">* 密码至少为6位</div></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="text" name ="passwords" id="passwords" onblur="checkWords()"/></td>
<td><div id="pwords">* 必须和初始密码保持一致<div></td>
</tr>
<tr>
<td>电话号码:</td>
<td><input type="text" name ="phone" id="phone" onblur="checkPhone()"/></td>
<td><div id="ph">* 只能输入11位数字!例:13595144582或08514785214</div></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name ="email" id="email" value="@" onclick="checkEmail()"/></td>
<td><div id="em">* E-mail格式不正确!例:jiie@163.com</div></td>
</tr>
<tr>
<td>QQ号码:</td>
<td><input type="text" name ="qqNum" id="qqNum" onblur="checkqqNum()"/></td>
<td><div id="qq">QQ号码只能输入数字</div></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交" />
<input type="reset" value="重置"/>
</td>
<td></td>
</tr>
<tr>
<td>
<font color="red">*为必填项</font>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
用HTML和jsp来实现一个注册页面
相关文章推荐
- html中将某个控件限制在框内的方法
- html使用笔记
- 最近的两个问题<input>与<frame src="/example/html/frame_a.html" name="showframe">
- html标记
- HTML标签,闭合还是不闭合?
- HTML-Ajax文件上传
- HTML中块级元素和行内元素
- html生成pdf
- HTML
- 使用HTML Purifier解决XSS问题
- html页面上轮播图片举例
- (HTML部分)特供.Net基础全套视频教程2014版(第十八天)(更新于2015年10月24日02:23:36)
- 对输入字符进行HTML转义 OR 去HTML标签
- html只允许输入的数据校验,只允许输入字母汉字数字等
- XHTML的使用规范
- html 标签
- html基础知识
- 有关Html页面节点的简单理解
- 有关Html页面节点的简单理解
- mac下利用Pandoc、LaTeX 转换markdown成html,pdf