需引用组件

<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Content/bootstrap/js/bootstrap.min.js"></script>
<link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/Content/bootstrapValidator/js/bootstrapValidator.min.js"></script>
<link href="~/Content/bootstrapValidator/css/bootstrapValidator.min.css" rel="stylesheet" />

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

常用验证规则

notEmpty: {
    message: '不能为空'
},
stringLength: {
    min: 6,
    max: 18,
    message: '长度必须在6到18位之间'
},
regexp: {
    regexp: /^[a-zA-Z0-9_]+$/,
    message: '只能包含大写、小写、数字和下划线'
},
emailAddress: {
    message: '邮箱地址格式有误'
},
numeric:{
    message:'只能输入数值'    
},
phone:{
    message:'手机号格式不正确'    
},
between:{
    message:''    
},
stringCase: {
    message: '只能包含大写字符',
    case: 'upper'//其他值或不填表示只能小写字符
},
different: {
    field: 'password',
    message: '和密码不能相同'
},
date: {
    format: 'YYYY/MM/DD',
    message: '日期无效'
},
digits: {
    message: '该值只能包含数字。'
},
choice: {
    min: 2,
    max: 4,
    message: '请选择2-4项'
},
identical: {
  field: 'confirmPassword',
  message: '确认密码和密码不同'
},
greaterThan: {
    value: 18,
    message: '必须大于18'
},
lessThan: {
    value: 100,
    message: '必须小于100'
},
remote: {//ajax验证。获得json数据:{"valid",true or false} ,向服务发送当前input name值
  url: 'exist2.do',//验证地址
  message: '用户已存在',//提示消息
  delay :  2000,//每输入一个字符,就发ajax请求,服务器压力还是太大,设置2秒发送一次ajax(默认输入一个字符,提交一次,服务器压力太大)
  type: 'POST'//请求方式
  /**自定义提交数据,默认值提交当前input value
     data: function(validator) {
    return {
      password: $('[name="passwordNameAttributeInYourForm"]').val(),
      whatever: $('[name="whateverNameAttributeInYourForm"]').val()
     };
   }*/
},
 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄