bootstrapValidator正则判断及ajax提交

 

var form = $('#form-test');

$(document).ready(function () {



form.bootstrapValidator({

live: 'enabled',

excluded: [':disabled', ':hidden', ':not(:visible)'],

submitButtons: '#btn-test',//指定提交按钮,如果验证失败则变成disabled,但我没试成功,反而加了这句话非submit按钮也会提交到action指定页面

message: '通用的验证失败消息',

feedbackIcons: {

valid: 'glyphicon glyphicon-ok',

invalid: 'glyphicon glyphicon-remove',

validating: 'glyphicon glyphicon-refresh'

},

fields: {

CUST_NAME: {

validators: {

notEmpty: {//检测非空,radio也可用

message: '请输入用户名'

},

stringLength: {//检测长度

min: 2,

max: 10,

},

regexp: {//正则验证

regexp: /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/,

message: '所输入的字符不符要求'

},

}

},

CONTACT_MAIL: {

validators: {

emailAddress: {//验证email地址

message: '请输入正确的邮件地址如:123@qq.com'

},

notEmpty: {//检测非空

message: '请输入邮箱'

},

}

},

CONTACT_TEL:{

validators:{

notEmpty:{

message:'手机号码不能为空'

},

stringlength:{

min:11,

max:11,

message:'请输入11位手机号码'

},

regexp:{

regexp:/^1[3|5|6|7|8|9]{1}[0-9]{9}$/,

message:'请输入正确的手机号码'

}

}

},

MSG_SUB:{

validators:{

notEmpty:{

message:'标题不能为空'

},

}

},

MSG_CONTENT:{

validators:{

notEmpty:{

message:'请填写内容'

}

}

}

},

}) ;

});



//弹窗提示


function showToast(msg,shortCutFunction)

{

toastr.options = {

"closeButton": true,

"debug": false,

"progressBar": true,

"positionClass": "toast-bottom-right",

"onclick": null,

"showDuration": "400",

"hideDuration": "1000",

"timeOut": "7000",

"extendedTimeOut": "1000",

"showEasing": "swing",

"hideEasing": "linear",

"showMethod": "fadeIn",

"hideMethod": "fadeOut"

}

toastr[shortCutFunction](msg,"提示");

}






$("#btn-test").click(function () {

var bv = form.data('bootstrapValidator');

bv.validate();

if(bv.isValid()) {

$.ajax({

url:url地址,

type:'post',

data:form.serialize(),

dataType:'jsonp',

jsonp:'callback',

success:function(data){



window.location.href = '../index.html';



},error:function(){

   showToast("测试中的错误","error");

}

})

}

});

// 特别提示 跨域 提交数据会提交2条  处理条件 让后台处理跨域问题

 

转载于:https://my.oschina.net/u/4005929/blog/2878508

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值