js登陆注册验证加美化怎么写

JavaScript0144

js登陆注册验证加美化怎么写,第1张

把前端代码写到jsp里面即可。js一般指JavaScript。是一种具有函数优先的轻量级,解释型或即时编译型的编程语言。js登陆注册验证加美化把前端代码写到jsp里面即可写出。js是作为开发Web页面的脚本语言而出名,但是它也被用到了很多非浏览器环境中。

页面就不写了,帮你把验证的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>

希望对你有用。

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

<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>