当前位置:首页 » 注册证书 » 注册js验证

注册js验证

发布时间: 2021-02-05 07:10:34

A. JavaScript注册表单的验证

function isCharsNotInBag (s, bag)
{
var i,c;
for (i = 0; i < s.length; i++)
{
c = s.charAt(i);
if (bag.indexOf(c) < 0)
return true;
}
return false;
} function InValidChar(s)
{
var haserrorChar;
var CorrectChar = ""
haserrorChar = isCharsNotInBag(s, CorrectChar);
return haserrorChar;
}

function orderuser(strs)
{

if (InValidChar(strs))
{
document.getElementById("uname").innerHTML ="用户名只能使用英文加数字组合";
document.getElementById("txtName").focus();

return;
}
if(strs.length<5)
{
document.getElementById("uname").innerHTML ="用户名不能低于5位";
document.getElementById("txtName").focus();

return;
}
var xmlHttp = new XMLHttpRequest();
var url="reg_ajax.aspx";
url= addparam(url,"users",strs);
url= addparam(url,"types","select");
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{

document.getElementById("uname").innerHTML = xmlHttp.responseText;
if(xmlHttp.responseText=="该用户名可以使用")
{

document.getElementById("txtPwd").focus();
document.getElementById("txtName").readOnly=true;
}
else
{

document.getElementById("txtName").focus();

}

}
}

}
function checkpwd()
{
var pwd = document.getElementById("txtPwd").value;

if (pwd.length<6)
{
document.getElementById("pwd").innerHTML="密码不能低于6位";
document.getElementById("txtPwd").focus();

return;
}
else
{
if (document.getElementById("txtPwd").value==document.getElementById("txtPwd2").value)
{
document.getElementById("pwd").innerHTML="两次密码相同";
document.getElementById("txtPwd").readOnly=true;
document.getElementById("txtPwd2").readOnly=true;
document.getElementById("Button1").disabled = "";
}
else
{
document.getElementById("pwd").innerHTML="两次密码不同";
document.getElementById("txtPwd").focus();

}
}

}

function checkform()
{
if (document.getElementById("yanzhengma").value.length<4)
{
alert("请输入验证码");
return;
}
else
{
var urlstr="regditaccept.aspx?uname=" + document.getElementById("txtName").value + "&upwd=" + document.getElementById("txtPwd").value + "&yzm=" + document.getElementById("yanzhengma").value +"&email="+ document.getElementById("txtMailbox").value ;

window.location.href=urlstr;

}

} <!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>
<title>无标题页</title>
<script type="text/javascript" src="../js/public_ajax.js"></script>
<script type="text/javascript" src="../js/reg_other.js">

</script>
</head>
<body onload="javascript:document.getElementById('txtName').focus();">
<form>
<table bgcolor="#cccccc" border="0" cellpadding="2" cellspacing="1" style="width: 477px;
height: 156px">
<tr>
<td align="center" bgcolor="#f7f7f7" width="80">
<span style="font-size: 10pt">用户名称:</span></td>
<td align="left" bgcolor="#f7f7f7" width="427">
<p>
<input id="txtName" name="txtName" onblur="orderuser(this.value)"
style="width: 185px" type="text" />
<span style="font-size: 10pt;color: #990000"><span class="hong1">*</span></span><span
id="uname" style="font-size: 10pt; color: #cc0000"></span></p>
</td>
</tr>
<tr>
<td align="center" bgcolor="#ffffff">
<span style="font-size: 10pt">您的密码:</span></td>
<td align="left" bgcolor="#ffffff">
<input id="txtPwd" maxlength="20" name="txtPwd" style="width: 185px"
type="password" />
<span class="hong1"><span style="font-size: 10pt; color: #990000">*</span> <span
id="rfv_Pwd" style="display: none; color: red"></span> </span>
</td>
</tr>
<tr>
<td align="center" bgcolor="#f7f7f7">
<span style="font-size: 10pt">确认密码:</span></td>
<td align="left" bgcolor="#f7f7f7">
<input id="txtPwd2" maxlength="20" name="txtPwd2" onblur="checkpwd()" style="width: 185px"
type="password" />
<span class="hong1"><span style="font-size: 10pt; color: #990000">* </span><span
id="pwd" style="font-size: 10pt; color: #cc0000"></span></span></td>
</tr>
<tr>
<td align="center" bgcolor="#f7f7f7">
<span style="font-size: 10pt">电子邮箱:</span></td>
<td align="left" bgcolor="#f7f7f7">
<input id="txtMailbox" class="text1" name="txtMailbox" style="width: 185px"
type="text" /></td>
</tr>
<tr>
<td align="center" bgcolor="#ffffff" style="height: 28px">
<span style="font-size: 10pt">验证码:</span></td>
<td align="left" bgcolor="#ffffff" style="height: 28px">
<input id="yanzhengma" type="text" width="110px" style="width: 97px" /><iframe frameborder="0"
scrolling="no" src="yanzhengma.aspx" style="width: 68px;
height: 22px"></iframe>
<span style="font-size: 10pt; color: #990000">(点击图片刷新验证码)</span></td>
</tr>
<tr>
<td align="center" bgcolor="#f7f7f7" colspan="2" nowrap="nowrap">
<input id="Button1" onclick="checkform()" disabled="disabled" style="border-right: #000000 1px solid; border-top: #000000 1px solid;
border-left: #000000 1px solid; width: 64px; border-bottom: #000000 1px solid;
height: 26px; background-color: #ff9900" type="button" value="注册" />
<input id="Button2" style="border-right: #000000 1px solid; border-top: #000000 1px solid;
border-left: #000000 1px solid; width: 64px; border-bottom: #000000 1px solid;
height: 26px; background-color: #ff9900" type="reset" value="重置" /></td>
</tr>
</table>
</form>
</body>
</html>

B. 求份完整的JS注册表单验证

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
form.input,div{margin:0; padding:0;}
body{font-size:12px; margin:0; padding:0;}
#login{width:1151; height:624px;}
.parent{width:100%; height:27px; line-height:27px;}
.parent label{display:inline-block;width:333px; height:27px;line-height:27px; text-align:right;}
.bor{padding-left:333px; color:#999;}
.three{width:308px; height:25px; border:1px solid #999;}
#email{width:196px; height:25px; border:1px solid #999;}
.wrong{background:url(images/wrong.png) no-repeat; padding-left:25px; color:#F00; display:inline-block; height:25px; line-height:25px;}
.right{background:url(images/right.png) no-repeat; padding-left:25px; color:#00F; display:inline-block; height:25px;line-height:25px;}
</style>
<title>注册界面</title>
</head>

<body>
<div id="login">
<form action="form" method="get" name="login" style="margin-top:24px">
<div class="parent"><label>邮箱地址:</label><input type="text" id="email" /> @
<select style="width:86px; height:20px;">
<option value="163.com">163.com</option>
<option value="126.com">126.com</option>
<option value="yeah.net">yeah.net</option>
</select>
</div>
<div class="bor">6-18个字符,区分大小写</div>
<div class="parent"><label>密码:</label><input type="password" id="pwd" class="three" /></div>
<div class="bor">6-16个字符,区分大小写</div>
<div class="parent"><label>确认密码:</label><input type="password" id="dpwd" class="three" /></div>
<div class="bor">请再次输入密码</div>
<div class="parent"><label>手机号码:</label><input type="text" id="phoneNum" class="three" /></div>
<div class="bor">密码遗忘或被盗时,可通过手机短信取回密码</div>
<div class="parent"><label>验证码:</label><input type="text"/></div>
<input type="button" id="dad" value="注册" style="position:relative;left:333px;" />
</form>
</div>
<script type="text/javascript">
for(i=0;i<4;i++){
document.getElementsByTagName("input")[i].onfocus=function(){
}
document.getElementsByTagName("input")[i].onblur=function(){
var spanLength=this.parentNode.getElementsByTagName("span").length;
if(spanLength>0){
this.parentNode.removeChild(this.nextSibling)
}
var id=this.getAttribute("id");
if(id=="email"){
emailReg=/^\w{6,18}$/
if(!emailReg.test(this.value)){
span=document.createElement("span")
spanTxt=document.createTextNode("您输入的格式有错误")
span.className="wrong"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}else{
span=document.createElement("span")
spanTxt=document.createTextNode("恭喜您输入正确")
span.className="right"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}
}
if(id=="pwd"){
pwdReg=/^\w{6,16}$/
if(!pwdReg.test(this.value)){
span=document.createElement("span")
spanTxt=document.createTextNode("您输入的格式有错误")
span.className="wrong"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}else{
span=document.createElement("span")
spanTxt=document.createTextNode("恭喜您输入正确")
span.className="right"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}
}
if(id=="dpwd"){
if(this.value!=document.getElementById("pwd").value||this.length<=0){
span=document.createElement("span")
spanTxt=document.createTextNode("您输入的格式有错误")
span.className="wrong"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}else{
span=document.createElement("span")
spanTxt=document.createTextNode("恭喜您输入正确")
span.className="right"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}
}
if(id=="phoneNum"){
phoneReg=/^1[3|4|5|8]\d{9}$/
if(!phoneReg.test(this.value)){
span=document.createElement("span")
spanTxt=document.createTextNode("您输入的格式有错误")
span.className="wrong"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}else{
span=document.createElement("span")
spanTxt=document.createTextNode("恭喜您输入正确")
span.className="right"
span.appendChild(spanTxt)
this.parentNode.appendChild(span)
}
}
}
document.login.getElementsByTagName("input")[i].onkeyup=function(){
this.blur();
this.focus();
}
}
document.getElementById("dad").onmousedown=function(){//onmousedown按下鼠标键
for(i=0;i<4;i++){
document.login.getElementsByTagName("input")[i].focus();//对所有的文本框进行验证
document.login.getElementsByTagName("input")[i].blur();//取消聚集
}
}
document.getElementById("dad").onmouseup=function(){//onmouseup弹起鼠标键
var errorNum=0;//
for(i=0;i<document.login.getElementsByTagName("span").length;i++){
if(document.login.getElementsByTagName("span")[i].className=="wrong"){
errorNum++;//加一次
}
}
if(errorNum==0){
document.login.submit()
}else{
alert("填写错误,请重新输入正确的内容。")
}
}
</script>
</body>
</html>
自己写着玩的
最好自己再修改下,看不懂我就没办法了。

C. js注册验证用户名首字母英文 登录密码和确认密码相同 email格式正确 *号项必填

我只给你提示,具体要么查资料,要么去网络搜了,然后多看看(希版望你好好学习,权只能说这个很简单很简单):
1、3的问题可以使用正则表达式完成(正则不会的,网络基本能得到答案)
2、这个我不知道你的作业会不会涉及后台,涉及后台的话使用AJAX异步+数据库查询+结果响应。不涉及后台,直接在js函数里定义变量,然后比较输入的内容是否相同就OK了
4、这个也是个内容的判断,你要是会了2,4这个也就没问题。
整个题目就是个怎么获取元素及内容,对比判断内容的信息,input标签里可以使用onchange作为触发方法事件,具体逻辑提示什么的就写在触发的函数里,这样就可以产生信息不对的提示了!
注意(纯手打,请不要追问具体代码,这个真的很简单,好好学学努力点,不会查查资料多看看对你有好处)

D. 请问下,在用html编写一个用户注册界面时,怎么加入js验证。

在Form中加一个onsubmit事件再在事件中写验证代码

E. js实现登录,注册,验证怎么写

js实现登录,注册,验证
不是简单的几句代码就可以实现的
它要结合后面,且一般还要搭建数据库环境
当然,用现成的框架可能更简单些(但你要搭建框架环境,并会使用它)
这个网上有很多现成的参考的,你可以自己查下

F. js如何实现注册时的智能判断

输入框后面加个 <span id="aaa"></span>
在你的判断函数中 加上如下代码
如果回成功答 document.getElementById("aaa").innerHTML="成功";
反之 document.getElementById("aaa").innerHTML="失败";

G. JS表单注册验证

把以下代码加到来body里试源一试 本应写成function 就是做个示意给你看看原理

昵称:
<inputtype="text"onclick="this.style.border='1px#cd1b1bsolid';document.getElementById('a').innerHTML='';"onblur="this.style.border='1px#000000solid';if(this.value==''){document.getElementById('a').innerHTML='昵称不能为空!';}"/><spanid="a"></span><br/><br/>
密码:
<inputtype="text"onclick="this.style.border='1px#cd1b1bsolid';document.getElementById('b').innerHTML='';"onblur="this.style.border='1px#000000solid';if(this.value==''){document.getElementById('b').innerHTML='密码不能为空!';}"/><spanid="b"></span>

H. 注册时 验证用的js代码

下面的代码测试通过,不过你说的密码不能重复是什么意思?
<script language="javaScript">
function checkReg(){
if (document.regForm.username.value == ""){
("提示:\n\n必须输入用户名!");
document.regForm.username.focus();
return false;
}
if (document.regForm.password.value == document.regForm.username.value){
alert ("提示:\n\n密码不能与用户名相同!");
document.regForm.password.focus();
return false;
}else if (document.regForm.password.value.length < 6){
alert ("提示:\n\n密码至少6位数!");
document.regForm.password.focus();
return false;
}else if (!isNaN(document.regForm.password.value)){
alert ("提示:\n\n密码不能全是数字!");
document.regForm.password.focus();
return false;
}
if(!(document.regForm.tel.value.match(/^(\d{3,4}\-)?\d{7,8}$/))){
alert ("提示:\n\n固定电话格式为:XXXX-XXXXXXX,XXXX-XXXXXXXX,XXX-XXXXXXX,XXX-XXXXXXXX,XXXXXXX,XXXXXXXX!");
document.regForm.tel.focus();
return false;
}
if(!(document.regForm.mobile.value.match(/^(\d{3})(\-)?(\d{8})$/))){
alert ("提示:\n\n11位手机号码格式为:XXXXXXXXXXX,XXX-XXXXXXXX!");
document.regForm.mobile.focus();
return false;
}
if(!(document.regForm.email.value.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/))){
alert ("提示:\n\nEmail地址错误!");
document.regForm.email.focus();
return false;
}

return true;
}
</script>
<table width="400" border="1" cellspacing="0" cellpadding="0" align="center">
<form method="post" action="reg.asp" name="regForm" onSubmit="return checkReg()">
<tr>
<td width="120" align="right">用户名:</td>
<td width="280"><input type="text" name="username" size="30"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="text" name="password" size="30"></td>
</tr>
<tr>
<td align="right">电话:</td>
<td><input type="text" name="tel" size="30"></td>
</tr>
<tr>
<td align="right">手机:</td>
<td><input type="text" name="mobile" size="30"></td>
</tr>
<tr>
<td align="right">邮箱: </td>
<td><input type="text" name="email" size="30"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" name="ok" value="注 册">
<input type="reset" name="reset" value="重 填">
</td>
</tr>
</form>
</table>

I. 用javascript做注册验证

给你写个简单的,一个文本框,一个密码框,验证两个都不能为空的。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function checkForm()
{
var f = document.forms[0];
if(f.username.value=='')
{
document.getElementById("userNameInfo").style.display="block";
return false;
}
if(f.password.value=='')
{
document.getElementById("passwordInfo").style.display="block";
return false;
}
return true;
}
</script>
</head>

<body>
<form action="#" method="post" onsubmit="return checkForm()">
用户名:<input type="text" name="username" /><div id="userNameInfo" style="display:none;"><font color="red">用户名不能为空</font></div><br/>
密码:<input type="password" name="password" /><div id="passwordInfo" style="display:none;"><font color="red">密码不能为空</font></div><br/>
<input type="submit" value="登录" />
</form>
</body>
</html>

J. js注册表单验证代码

||

‍JS函数:

functioncheck(){
varusername=document.getElementById("username").value;
varpass1=document.getElementById("password").value;
varpass2=document.getElementById("confirm_password").value;

if(username==""||username==NULL||pass1==""||pass1==NULL||pass2==NULL||pass2==""){
alert("用户名或密码不得为空!");
returnfalse;
}
}

表单提交版的时候验证:权

<inputname="reg"type="submit"value="提交"onclick="returncheck()"/>

自己补全。

热点内容
美发店认证 发布:2021-03-16 21:43:38 浏览:443
物业纠纷原因 发布:2021-03-16 21:42:46 浏览:474
全国著名不孕不育医院 发布:2021-03-16 21:42:24 浏览:679
知名明星确诊 发布:2021-03-16 21:42:04 浏览:14
ipad大专有用吗 发布:2021-03-16 21:40:58 浏览:670
公务员协议班值得吗 发布:2021-03-16 21:40:00 浏览:21
知名书店品牌 发布:2021-03-16 21:39:09 浏览:949
q雷授权码在哪里买 发布:2021-03-16 21:38:44 浏览:852
图书天猫转让 发布:2021-03-16 21:38:26 浏览:707
宝宝水杯品牌 发布:2021-03-16 21:35:56 浏览:837