jquery.validate.js form表单验证插件


jquery form验证插件

第一步引入bfwone,data中要注入依赖jquery

第二步执行插件方法

示例如下

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>BFW DEMO JS PAGE</title>
    <script id="bfwone" data="dep=jquery.17" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script>
        bready(function() {
            use(["jquery-validate"], function() {
                $('form').validate({
                    onFocus: function() {
                        this.parent().addClass('active');
                        return false;
                    },
                    onBlur: function() {
                        var $parent = this.parent();
                        var _status = parseInt(this.attr('data-status'));
                        $parent.removeClass('active');
                        if (!_status) {
                            $parent.addClass('error');
                        }
                        return false;
                    }
                });
                $('form').on('submit', function(event) {
                    event.preventDefault();
                    $(this).validate('submitValidate'); //return boolean;
                });
            });
        });
    </script>

</head>
<body>
    <form>
        <div class="form_control">
            <input class="required" value="315359131@qq.com" type="text" name="email" data-tip="请输入您的邮箱" data-valid="isNonEmpty||isEmail" data-error="email不能为空||邮箱格式不正确">
        </div>
        <div class="form_control">
            <input class="required" value="123456789" type="password" data-tip="请输入您的密码" data-valid="isNonEmpty||between:6-16" data-error="密码不能为空||密码长度6-16位" name="nickname">
        </div>
        <div class="form_control">
            <input class="required" value="王大锤" type="text" name="email" data-tip="请输入您的姓名" data-valid="isNonEmpty||onlyZh||between:2-5" data-error="姓名不能为空||姓名只能为中文||姓名长度为2-5位">
        </div>
        <div class="form_control">
            <span class="required" data-valid="isChecked" data-error="性别必选" data-type="radio">
                <label><input type="radio" name="sex">男</label>
                <label><input type="radio" name="sex">女</label>
                <label><input type="radio" name="sex">未知</label>
            </span>
        </div>
        <div class="form_control">
            <span class="required" data-valid="isChecked" data-error="标签至少选择一项" data-type="checkbox">
                <label><input type="checkbox" name="label">红</label>
                <label><input type="checkbox" name="label">绿</label>
                <label><input type="checkbox" name="label">蓝</label>
            </span>
        </div>
        <div class="form_control">
            <select class="required" data-valid="isNonEmpty" data-error="省份必填">
                <option value="">请选择省份</option>
                <option value="001">001</option>
                <option value="002">002</option>
                <option value="003">003</option>
                <option value="004">004</option>
                <option value="005">005</option>
                <option value="006">006</option>
                <option value="007">007</option>
                <option value="008">008</option>
                <option value="009">009</option>
                <option value="010">010</option>
            </select>
        </div>
        <div>
            <input type="submit" value="提交">
        </div>
    </form>

</body>
</html>


立即下载jquery.validate.js查看所有js插件

网友评论0

程序员在线工具箱