zoukankan      html  css  js  c++  java
  • BootstrapValidator验证表单用法

    引入文件

    <link rel="stylesheet" href="css/bootstrap.css"/>
    <link rel="stylesheet" href="css/bootstrapValidator.min.css"/>
     
    <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
     
    <script type="text/javascript" src="js/bootstrapValidator.min.js"></script>
    

    html

    <form form=“testForm” role="form">
        <div class="form-group">
            <label>用户名</label>
            <input type="text" class="form-control" name="username" />
        </div>
        <div class="form-group">
            <label>Email</label>
            <input type="text" class="form-control" name="email" />
        </div>
    </form>
    

    js

        $(#testForm).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    message: '用户名输入格式不正确',
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 18,
                            message: '用户名在6-18字之内'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_]+$/,
                            message: '输入数字与字母组合'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        emailAddress: {
                            message: '请输入正确的邮箱地址'
                        }
                    }
                }
            }
        });
    

    jQuery API:http://bv.doc.javake.cn/examples/

  • 相关阅读:
    PHP实现4种排序算法
    PHP反射获取当前函数的内容
    PHP递归目录的5种方法
    生成随机数组
    empty、isset、is_null的比较
    PHP哈希表碰撞攻击
    XMLHttpRequest的跨域请求
    CI框架SESSION重写
    PHP开发第一个扩展
    PHP面试题集之基础题
  • 原文地址:https://www.cnblogs.com/hcrs/p/4933128.html
Copyright © 2011-2022 走看看