Validform

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<link rel="stylesheet" type="text/css" href="bootstrap3/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="Validform/css/style.css">
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="Validform/js/Validform_v5.3.2.js"></script>
<style type="text/css">
body{
background: #fff;
}
.form-control{
width: 300px;
float: left;
}
.col-sm-10{
height: 34px;
line-height: 34px;
}
</style>
<script type="text/javascript">
$(function(){
// $(".registerform").Validform();

var demo=$(".registerform").Validform({
tiptype:3,
label:".label",
showAllError:true,
datatype: {
"zh1-6": /^[\u4E00-\u9FA5\uf900-\ufa2d]{1,6}$/
},
ajaxPost:true
});
// $(".ajaxpost").click(function(){
// demo.ajaxPost();
// return false;
// });

/**

var demo=$(".registerform").Validform({
tiptype:3,
label:".label",
showAllError:true,
datatype:{
"zh1-6":/^[\u4E00-\u9FA5\uf900-\ufa2d]{1,6}$/,

//----------------身份证号验证---------------------------
"idcard":function(gets,obj,curform,datatype){
//该方法由佚名网友提供;

var Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ];// 加权因子;
var ValideCode = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ];// 身份证验证位值,10代表X;

if (gets.length == 15) {
return isValidityBrithBy15IdCard(gets);
}else if (gets.length == 18){
var a_idCard = gets.split("");// 得到身份证数组
if (isValidityBrithBy18IdCard(gets)&&isTrueValidateCodeBy18IdCard(a_idCard)) {
return true;
}
return false;
}
return false;

function isTrueValidateCodeBy18IdCard(a_idCard) {
var sum = 0; // 声明加权求和变量
if (a_idCard[17].toLowerCase() == 'x') {
a_idCard[17] = 10;// 将最后位为x的验证码替换为10方便后续操作
}
for ( var i = 0; i < 17; i++) {
sum += Wi[i] * a_idCard[i];// 加权求和
}
valCodePosition = sum % 11;// 得到验证码所位置
if (a_idCard[17] == ValideCode[valCodePosition]) {
return true;
}
return false;
}

function isValidityBrithBy18IdCard(idCard18){
var year = idCard18.substring(6,10);
var month = idCard18.substring(10,12);
var day = idCard18.substring(12,14);
var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));
// 这里用getFullYear()获取年份,避免千年虫问题
if(temp_date.getFullYear()!=parseFloat(year) || temp_date.getMonth()!=parseFloat(month)-1 || temp_date.getDate()!=parseFloat(day)){
return false;
}
return true;
}

function isValidityBrithBy15IdCard(idCard15){
var year = idCard15.substring(6,8);
var month = idCard15.substring(8,10);
var day = idCard15.substring(10,12);
var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));
// 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法
if(temp_date.getYear()!=parseFloat(year) || temp_date.getMonth()!=parseFloat(month)-1 || temp_date.getDate()!=parseFloat(day)){
return false;
}
return true;
}
}
//--------------------------------------------------


},
ajaxPost:true,
// tiptype:2,

//密码强度验证
usePlugin:{
passwordstrength:{
minLen:6,//设置密码长度最小值,默认为0;
maxLen:18,//设置密码长度最大值,默认为30;
trigger:function(obj,error){
//该表单元素的keyup和blur事件会触发该函数的执行;
//obj:当前表单元素jquery对象;
//error:所设密码是否符合验证要求,验证不能通过error为true,验证通过则为false;

//console.log(error);
if(error){
obj.parent().find(".Validform_checktip").show();
obj.parent().find(".passwordStrength").hide();
}else{
obj.parent().find(".Validform_checktip").hide();
obj.parent().find(".passwordStrength").show();
}
}
}
}
//-----------

});

demo.tipmsg.w["zh1-6"]="请输入1到6个中文字符!";

demo.addRule([{
ele:".inputxt:eq(0)",
datatype:"zh2-4"
},
// {
// ele:".inputxt:eq(1)",
// datatype:"*6-20"
// },
//
// {
// ele:".inputxt:eq(2)",
// datatype:"*6-20",
// recheck:"userpassword"
// },
{
ele:"select",
datatype:"*"
},
{
ele:":radio:eq(1)",
datatype:"*"
},
// {
// ele:":checkbox:first",
// datatype:"*"
// }
]);


**/

});
</script>
<body>
<div class="container">
<form action="" method="POST" class="form-horizontal registerform">
<div class="form-group">
<label class="col-sm-2 control-label">用户名:</label>
<div class="col-sm-10">
<input type="text" class="form-control" datatype="zh2-4" sucmsg="用户名验证通过!" nullmsg="用户名不能为空" errormsg="名称为2~4个汉字">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密码</label>
<div class="col-sm-10">
<input type="password" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">提交</button>
</div>
</div>
</form>
</div>
</body>
</html>

 

转载于:https://www.cnblogs.com/suxiaolong/p/6654185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值