手机端表单验证插件

html结构

<form id="myform">
<p><label>手机号</label><input name="user_phone" type="text" placeholder="请输入您的手机号码" data-pattern="^0?1[3|4|5|8][0-9]\d{8}$" data-required="true" data-descriptions="userphone" data-describedby="userphone-description"/></p>
<p><label>姓名</label><input name="user_name" type="text" placeholder="请填写您的姓名" data-required="true" data-descriptions="username" data-describedby="username-description"></p>
<p><label>职位</label><input name="position_name" type="text" placeholder="请填写您的职位" data-required="true" data-descriptions="positionname" data-describedby="positionname-description"></p>
<p><label>股票代码</label><input name="stock_code" type="text" placeholder="请填写您公司的股票代码" data-required="true" data-descriptions="stockcode" data-describedby="stockcode-description"/></p>
<p><label>公司名称</label><input name="company_name" type="text" placeholder="请填写您公司的名称" data-required="true" data-descriptions="companyname" data-describedby="companyname-description"/></p>
</form>

css部分
.field-invalid{
border-color:#a94442;
}
.field-invalidmsg{
color:#a94442;
}
.field-validmsg{
color:#3c763d;
}
.field-tooltipWrap{
position: absolute;
left: 0;
top: 0;
width: 100%;
z-index: 19891014;
}
.field-tooltipInner{
pointer-events: none;
display: table;
position:fixed;
left:0;
top:0;
width:100%;
height:100%;
}
.field-tooltip{
display: table-cell;
vertical-align: middle;
text-align: center;
}
.field-tooltip .field-invalidmsg,
.field-tooltip .field-validmsg{
color: #fff;
}
.field-tooltip .zvalid-resultformat{
display: inline-block;
position: relative;
font-weight:bold;">rgba(0,0,0,0.8);
color: #fff;
padding: 10px 15px;
font-size: 14px;
border-radius: 6px;
box-shadow: 0 0 8px rgba(0,0,0,.1);
pointer-events: auto;
animation-name:fieldTipBounceIn;
-webkit-animation-name:fieldTipBounceIn;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: .18s;
animation-duration: .18s;
}

@-webkit-keyframes fieldTipBounceIn{

0% {
opacity: 0;
-webkit-transform: scale3d(.3, .3, .3);
transform: scale3d(.3, .3, .3);
}
100% {
opacity: 1;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}


@keyframes fieldTipBounceIn
{


0% {
opacity: 0;
-webkit-transform: scale3d(.3, .3, .3);
transform: scale3d(.3, .3, .3);
}
100% {
opacity: 1;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}



js部分
//表单验证
$("#myform").mvalidate({
type:1,
onKeyup:true,
sendForm:true,
firstInvalidFocus:false,
valid:function(event,options){
//点击提交按钮时,表单通过验证触发函数
//alert("验证通过!接下来可以做你想做的事情啦!");
alert('通过了验证');
event.preventDefault();
},
invalid:function(event, status, options){
//点击提交按钮时,表单未通过验证触发函数
// alert("表单未通过验证!");

},
eachField:function(event,status,options){
//点击提交按钮时,表单每个输入域触发这个函数 this 执向当前表单输入域,是jquery对象
// alert("每个都弹出!");
},
eachValidField:function(val){},
eachInvalidField:function(event, status, options){},
conditional:{
},
descriptions:{
username:{
required : '请输入姓名'
},
userphone : {
required : '请输入手机号码',
pattern : '手机号格式不正确'
},
stockcode : {
required : '请输入股票代码'
},
positionname : {
required : '请输入您的职位'
},
companyname : {
required : '请输入公司名称'
}

}
});


下载插件
jquery-mvalidate.js
mvalidate.css

转载于:https://www.cnblogs.com/huancheng/p/7771572.html

js代码 [removed] function checkreg() { var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})) \d{8})$/; if(document.form1.name.value == "") { //alert("请输入您的用户名!"); document.getElementById("tish")[removed] = "<font color='red'>请输入您的用户名!</font>"; form1.name.focus(); return false; } document.getElementById("tish")[removed] = "<font color='green'>正确</font>"; // if (document.form1.User.value.length<4 || document.form1.User.value.length>15) // { // alert("用户名长度限制在4-15位!"); // form1.User.focus(); // return false; // } if(document.form1.password.value == "") { //alert("请输入密码!"); document.getElementById("ts")[removed] = "<font color='red'>请输入密码</font>"; form1.password.focus(); return false; } if(document.form1.password.value.length < 6 || document.form1.password.value.length > 20) { //alert("密码长度限制在6-20位!"); document.getElementById("ts")[removed] = "<font color='red'>密码长度限制在6-20位!</font>"; form1.password.focus(); return false; } document.getElementById("ts")[removed] = "<font color='green'>正确</font>"; if(document.form1.password.value != document.form1.Pwdagain.value) { document.getElementById("tishi")[removed] = "<font color='red'>两次密码不相同</font>"; form1.password.focus(); return false; } document.getElementById("tishi")[removed] = "<font color='green'>正确</font>"; // alert("注册成功!"); // location.href="http://www.lanrenzhijia.com"; if(!myreg.test(document.form1.phone.value)) { document.getElementById("tss")[removed] = "<font color='red'>手机号码错误</font>"; form1.password.focus(); return false; } document.getElementById("tss")[removed] = "<font color='green'>正确</font>"; if(document.form1.code.value == "") { document.getElementById("tsi")[removed] = "<font color='red'>验证码不能为空</font>"; form1.code.focus(); return false; } document.getElementById("tsi")[removed] = "<font color='green'>正确</font>"; location.href="homepage.html"; } function sendMessage(t) { var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})) \d{8})$/; if(!myreg.test(document.form1.phone.value)) { alert('请输入有效的手机号码!'); return false; } // document.form1.dynamic.disabled = true; for(i = 1; i <= t; i ) { window.setTimeout("update_p(" i "," t ")", i * 1000); } } function update_p(num, t) { if(num == t) { document.form1.dynamic.value = " 重新发送 "; document.form1.dynamic.disabled = false; } else { printnr = t - num; document.form1.dynamic.value = " (" printnr ")秒后重发"; } } [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值