一个简单的表单验证JS

来源:互联网 发布:网络分销平台排行 编辑:程序博客网 时间:2024/05/16 17:09

一个简单的表单验证JS

这个表单验证支持空值,长度,范围,群组,ajax

示例效果

验证模式1 验证模式2

类别类别1 类别2 类别3 类别4项目项目1 项目2 项目3 项目4 

 

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Validator.add({
    id:'Name', name: '用户名', type: 'require length ajax', min: 5, max: 200,
    ajax: {
        value:function() {
            if (document.getElementById('Name').value == 'known')
                return true;
            else
                return false;
        },
        message:'用户名已经存在!'
    }
});
Validator.add({ id: 'Password', name: '密码', type: 'require' });
Validator.add({ id: 'Type', name: '类别', type: 'group' });
Validator.add({ id: 'Item', name: '项目', type: 'group' });
if (Validator.validate(document.forms[0].m[0].checked ? 1 : 2)) {
    Pop.confirm({
        info:'确认送出?',
        ok:function() { Pop.wait(); document.forms[0].submit(); },
        cancel:function() { return false; }
    });
}
return false;


0 0
原创粉丝点击