function checkEmail( )
{
var e=document.myform.email.value
if (e.length==0)
{
alert("电子邮件不能为空!")
return
}
if (e.indexOf("@",0)==-1)
{
alert("格式不正确\n必须包含@符号!")
return
}
if (e.indexOf(".",0)==-1)
{
alert("格式不正确\n必须包含.符号!")
return
}
document.write(“成功!")
}
//函数名:chkemail//功能介绍:检查是否为Email Address
//参数说明:要检查的字符串
//返回值:0:不是 1:是
function chkemail(a)
{ var i=a.length
var temp = a.indexOf('@')
var tempd = a.indexOf('.')
if (temp >1) {
if ((i-temp) >3){
if ((i-tempd)>0){
return 1
}
}
}
return 0
}
用ajax有段代码 你参考下
<%@ page contentType="text/htmlcharset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title></title>
</head>
<script language="javascript">
var xmlHttp
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest()
}
}
function checkloginname()
{
var loginname=document.all.personregedit.loginname.value
if(loginname==""||!checklength(loginname,4,16))
{
document.getElementById("lname").innerHTML=" <img src='../images/31.gif' border='0' /><font color='#FF0000' size='-1'>该用户名不合法,快重新填写!</font>"
document.all.personregedit.loginname.value=""
document.all.personregedit.loginname.focus()
return
}
createXMLHttpRequest()
xmlHttp.onreadystatechange=checknamers
xmlHttp.open("post","loginname.checkname?name="+loginname)
xmlHttp.send(null)
}
function checknamers()
{
var responseContext
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
responseContext=xmlHttp.responseText
if(responseContext.indexOf("null")==-1)
{
document.getElementById("lname").innerHTML=" <img src='../images/09.gif' border='0' /><font color='#FF0000' size='-1'>Sorry!该用户名已被注册,请重新填写!</font>"
document.all.personregedit.loginname.value=""
document.all.personregedit.loginname.focus()
}else
{
document.getElementById("lname").innerHTML=" <img src='../images/04.gif' border='0' /><font color='#0000FF' size='-1'>恭喜!该用户名可用!</font>"
}
}
}
}
function checklength(thestring,a,b)
{
var string=thestring
var minl=parseInt(a)
var maxl=parseInt(b)
var thelength=string.length
if(thelength>=minl&&thelength<=maxl)
{
return true
}else
{
return false
}
}
function checkrpsw()
{
var password=document.all.personregedit.password.value
var repassword=document.all.personregedit.repassword.value
if(repassword!=password)
{
document.getElementById("ps").innerHTML=" <img src='../images/31.gif' border='0' /><font color='#FF0000' size='-1'>你两次输入的密码不同,重来吧!</font>"
document.all.personregedit.password.value=""
document.all.personregedit.repassword.value=""
document.all.personregedit.password.focus()
}else
{
document.getElementById("ps").innerHTML=""
}
}
function checkemail()
{
var email=document.all.personregedit.email.value
if((email!=null&&email!="")&&(email.indexOf("@")==-1||email.indexOf("@")==0||email.indexOf("@")==email.length-1))
{
alert("您输入的邮箱格式有误,请重新填写!")
document.all.personregedit.email.value=""
document.all.personregedit.email.focus()
}
}
function submitform()
{
checkrpsw()
if(document.all.personregedit.personname.value==null||document.all.personregedit.personname.value=="")
{
alert("姓名是必填项!")
}else if(document.all.personregedit.loginname.value==null||document.all.personregedit.loginname.value==""){
alert("用户名是必填项!")
}else if(!checklength(document.all.personregedit.loginname.value,4,16)){
alert("用户名的长度必须在4-16个字符之间!")
}else if(document.all.personregedit.password.value==null||document.all.personregedit.password.value==""){
alert("密码不能为空!")
}else if(!checklength(document.all.personregedit.password.value,4,16)){
alert("用户密码的长度必须在4-16个字符之间!")
}else if(document.all.personregedit.email.value==null||document.all.personregedit.email.value==""){
alert("请填写邮箱地址!")
}else{
document.all.personregedit.action="regeditaction.jsp"
document.all.personregedit.submit()
}
}
</script>
<body>
<form name="personregedit" method="post" action="">
<input type="hidden" name="regedittype" value="person" />
<table width="98%" height="98%" cellpadding="1" cellspacing="1">
<tr>
<td>
<table width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><font color="#0000FF" size="+2" face="楷体_GB2312">个 人 信 息 注 册</font><br /><br /><br /></td>
</tr>
<tr>
<tr>
<td align="right"><a href="regeditunit.jsp"><font color="#0000FF" size="-1" face="新宋体">团 体 信 息 注 册 </font></a><br /><br /><br /></td>
</tr>
<td><table width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="right" width="19%" valign="top">姓 名:</td>
<td width="42%" align="left" valign="top">
<input name="personname" type="text" size="40" value="" /></td>
<td width="39%" align="left"> <img src="../images/tutu02.gif" border="0" /><font size="2" color="#485EF2">请填写真实姓名</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">用户名:</td>
<td align="left" valign="top">
<input name="loginname" type="text" size="40" value="" onblur="checkloginname()" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onmouseover="value=value.replace(/[^a-zA-Z0-9]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Z0-9]/g,''))"/>
<div id="lname"></div></td>
<td> <img src="../images/tutu02.gif" border="0" /><font size="2" color="#485EF2">即登录名,只能为数字和英文字母的组合(4-16个字符)!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">密 码:</td>
<td align="left" valign="top">
<input name="password" type="password" size="44" value="" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onmouseover="value=value.replace(/[^a-zA-Z0-9]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Z0-9]/g,''))"/></td>
<td> <img src="../images/tutu02.gif" border="0" /><font size="2" color="#485EF2">即登录密码,只能为数字和英文字母的组合(4-16个字符)!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">重复密码:</td>
<td align="left" valign="top">
<input name="repassword" type="password" size="44" value="" onblur="checkrpsw()" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onmouseover="value=value.replace(/[^a-zA-Z0-9]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Z0-9]/g,''))"/>
<div id="ps" ></div></td>
<td> <img src="../images/tutu02.gif" border="0" /><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">学 院:</td>
<td align="left" valign="top">
<input name="colleage" type="text" size="40" value="" /></td>
<td> <font size="2" color="#485EF2">选填内容!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">班 级:</td>
<td align="left" valign="top">
<input name="theclass" type="text" size="40" value=""/></td>
<td> <font size="2" color="#485EF2">选填内容!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">邮 箱:</td>
<td align="left" valign="top">
<input name="email" type="text" size="40" value="" onblur="checkemail()"/></td>
<td> <img src="../images/tutu02.gif" border="0" /><font size="2" color="#485EF2">请确认邮箱可以正常使用,它是您取回密码和接收管理员信息的唯一方式!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%" valign="top">注册协议:</td>
<td align="left" valign="top">
<textarea name="textarea" cols="40" rows="5" readonly="readonly" style="background-color:#CCCCCC">
用户成功注册后... </textarea>
<br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%"></td>
<td align="left"><font color="#FF0000" face="新宋体" size="2">注册用户注册后默认同意以上注册协议,请认真阅读后提交注册信息!</font><br />
<br /></td>
</tr>
<tr>
<td align="right" width="19%"></td>
<td align="left">
<input name="button" type="button" onclick="submitform()" value="提 交"/>
<input name="reset" type="reset" value="重 填"/></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)