`
Francis.lin
  • 浏览: 4230 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

ValidForm 表单验证插件

阅读更多

<div class="iteye-blog-content-contain" style="font-size: 14px"></div>

ajaxurl:实时验证功能.

例,ajaxurl : "<%=path%>/user/user!randnum.json"

/**
	 * 验证码是否输入成功
	 */
	public void randnum() {

		Map<String, String> hashmap = new HashMap<String, String>();

		HttpSession hs = getHttpSession();

		if (hs.getAttribute("randnum") != null) {

			String s_randnum = (String) hs.getAttribute("randnum");

			if (!model.getParam().equals(s_randnum)) {

				hashmap.put("info", "验证码错误,请重新输入!");
				hashmap.put("status", "n");
			} else {

				hashmap.put("info", "");
				hashmap.put("status", "y");
			}

			model.setMessage_(SystemStatusCode.OPERATE_OK, "get success", "", "验证成功", hashmap);
		}
	}

 

 返回的一定是json数据格式的,{"info":"验证码错误,请重新输入!","status":"n"} 必须有这info和status两个字段,信息自己定义。一般返回这种json格式即可。前台不用再处理,已封装好。

 

密码强度插件:passwordStrength-min.js 引入即可。然后js中加入usePlugin即可.

<script type="text/javascript">
	$(function() {

		var demo = $(".registerform").Validform({
			tiptype : 2,
			showAllError : true,
			label : ".label",
			btnSubmit : "#btn_sub",
			ajaxPost : true,
			postonce : true,
			usePlugin:{
				passwordstrength:{
					minLen:6,//设置密码长度最小值,默认为0;
					maxLen:20,//设置密码长度最大值,默认为30;
					trigger:function(obj,error){
						if(error){
							obj.parent().next().find(".Validform_checktip").show();
							obj.parent().next().find(".passwordStrength").hide();
						}else{
							obj.parent().next().find(".Validform_checktip").hide();
							obj.parent().next().find(".passwordStrength").show();	
						}
					}
				}
			},
			callback : function(data) {
				var userCode = $('#userCode').val();
				if(data.status == "y") {

					var url="<%=path%>/user/user-activating.jsp?userCode="+userCode+"&password="+$('#register_password').val();

					setTimeout(window.location.href = url, 3000);
				}
			}
		});

		demo.addRule([ {
			ele : ".inputxt:eq(0)",
			datatype : "m | e",
			tip : "Email/手机号码",
			nullmsg : "请输入中国大陆手机号或常用邮箱,可用于登录和找回密码",
			errormsg : "手机或邮箱格式有误,请重新输入",
			sucmsg : " ",
			ajaxurl : "<%=path%>/user/user!regis.json"
		}, {
			ele : ".inputxt:eq(1)",
			datatype : "*6-20",
			tip : "昵称",
			nullmsg : "请输入您的昵称",
			sucmsg : " ",
			errormsg : "昵称至少6个字符,最多20个字符!"
		}, {
			ele : ".inputxt:eq(2)",
			datatype : "*6-20",
			sucmsg : " ",
			nullmsg : "请输入您的密码",
		}, {
			ele : ".inputxt:eq(3)",
			datatype : "*6-20",
			recheck : "password",
			nullmsg : "请再输入一次密码",
			sucmsg : " ",
			errormsg : "您两次输入的账号密码不一致"
		}, {
			ele : ".inputxt:eq(4)",
			datatype : "*4-4",
			nullmsg : "请输入验证码",
			errormsg : "验证码输入错误",
			sucmsg : " ",
			ajaxurl : "<%=path%>/user/user!randnum.json"
		}]);
	});
</script>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics