1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| <form name="newregform" id="newregform" method="post" action="/reg.me?act=doreg">
<input name="uname" id="uname" type="text" />
<span class="onError" id="unameTip"></span>
<li>
<div class="biaospan3">密码:</div>
<div class="biaospan2"><input name="pwd1" id="pwd1" type="password"/></div>
<div class="lright"><span class="onError" id="pwd1Tip"></span></div>
</li>
<li>
<div class="biaospan3">确认密码:</div>
<div class="biaospan2"><input name="pwd2" id="pwd2" type="password"/></div>
<div class="lright"><span class="onError" id="pwd2Tip"></span></div>
</li>
<li>
<div class="biaospan3">电子邮箱:</div>
<div class="biaospan2"><input name="email" id="email" type="text" size="30"/></div>
<div class="lright"><span class="onError" id="emailTip"></span></div>
</li>
</form>
//下面是js代码
<script type="text/javascript">
$(document).ready(function(){
$.formValidator.initConfig({validatorgroup:"1",formid:"newregform",onerror:function(msg){alert(msg)}});
$("#uname").formValidator({onshow:"请输入昵称",onfocus:"最多20个字符",oncorrect:"输入正确"}).inputValidator({min:1,max:20,empty:{leftempty:false,rightempty:false,emptyerror:"昵称两边不能有空格"},onerror:"昵称不能为空"}).ajaxValidator({
type : "post",
cache : false,
url : "/servlet/newspace",
datatype : "html",
addidvalue : true,
data : "act=new_vname",
success : function(data){
if(data == "success" ){
return true;
}else{
return false;
}
},
buttons: $("#regbtn"),
error: function(){alert("服务器忙,请重试");},
onerror : "您注册的昵称已存在",
onwait : "正在对昵称进行校验..."
});
$("#email").formValidator({onshow:"请输入邮箱",onfocus:"最多80个字符",oncorrect:"输入正确"}).inputValidator({min:1,max:80,empty:{leftempty:false,rightempty:false,emptyerror:"邮箱两边不能有空格"},onerror:"邮箱不能为空"}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"邮箱格式不正确"}).ajaxValidator({
type : "post",
cache : false,
addidvalue : true,
url : "/servlet/newspace",
datatype : "html",
data : "act=new_vemail",
success : function(data){
if(data == "success" ){
return true;
}else{
return false;
}
},
buttons: $("#regbtn"),
error: function(){alert("服务器忙,请重试");},
onerror : "您注册的邮箱已存在",
onwait : "正在对邮箱进行校验..."
});
$("#pwd2").formValidator({onshow:"确认密码不能为空",onfocus:"最多20个字符",oncorrect:"输入正确"}).inputValidator({min:1,max:20,empty:{leftempty:false,rightempty:false,emptyerror:"确认密码两边不能有空格"},onerror:"确认密码不能为空"}).compareValidator({desid:"pwd1",operateor:"=",datatype:"string",onerror:"确证密码不一致"});
});
</script> |