利用Javascript实现用户注册信息检查

JavaScript015

利用Javascript实现用户注册信息检查,第1张

页面就不写了,帮你把验证的js方法写好了。 调用的话,你在form的onsubmit时调用就行。

<script>

    //用户名要以字母开头;

var isUserName = function(s){  

  var patrn=/^[a-zA-Z]+$/  

   if (!patrn.exec(s))

       return false  

        return true  

//两次输入的密码需要一样;

var isPassword = function(s1,s2){

    if(!s1==s2)

        return false  

        return true  

}

//输入的EMAIL地址中必须要有’@’ 

var isEmail = function(s){

  var patrn=/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/  

   if (!patrn.exec(s))

       return false  

        return true  

//有些输入项是必填项,不能为空;

var isEmpty = function(s){

   var patrn=/^[\s\S]+$/  

   if (!patrn.exec(s))

       return false  

        return true  

</script>

希望对你有用。

function RegFeiQ(){  

     var regEdit = new RegEdit()  

     var x = regEdit.regRead("HKEY_CLASSES_ROOT\\ABC")  

     if(x==""){

         alert("ABC不存在")

     }

}

/** 

 * 注册表编辑器,封装对注册表的操作 

 */  

function RegEdit(){  

 this.shell = new ActiveXObject("WScript.Shell")  

 this.regRead = regRead  

 this.regWrite = regWrite  

 this.regDelete = regDelete  

}  

  

/** 返回名为 strName 的注册键或值。 

 * @param strName 要读取的键或值。如果 strName 以反斜线 (\) 结束,本方法将返回键,而不是值 

 * @return 名为 strName 的注册键或值 

 */  

function regRead(strName){  

 var val = null  

 try {  

  val = this.shell.regRead(strName)  

 } catch (e) {  

  alert(e.message)  

 }  

 return val  

}  

  

/** 设置 strName 指定的注册键或值 

 * @param strName 要写的键或值的名称.如果 strName 以反斜线 (\) 结束,本方法将返回键,而不是值 

 * @param anyValue 要写入键或注册表值中的值 

 * @param strType 可选项。要保存到注册表中的值的数据类型REG_SZ、REG_EXPAND_SZ、REG_DWORD、REG_BINARY 

 */  

function regWrite(strName,anyValue,strType){  

 if(strType == null)  

  strType = "REG_SZ"  

 this.shell.regWrite(strName,anyValue,strType)  

}  

  

/** 从注册表中删除 strName 指定的键或值。 

 * @param strName 要删除的键或值的名字。如果 strName 以反斜线 (\) 结束,本方法将删除键,而不是值 

 */  

function regDelete(strName){  

 this.shell.regDelete(strName)  

}  

////////////////注册表编辑类end//////////////////////

借助网络资料,希望对你有帮助!谢谢采纳

下面的代码测试通过,不过你说的密码不能重复是什么意思?

<script language="javaScript">

function checkReg(){

if (document.regForm.username.value == ""){

alert ("提示:\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>