zoukankan      html  css  js  c++  java
  • 一个简单的表单验证JS

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

    示例效果

    验证模式1 验证模式2

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

    示例代码

    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;
    

    代码下载

  • 相关阅读:
    Eclipse慢慢学会的快捷键
    换行和flush()
    接口Interface
    对象的转型
    抽象类和抽象函数
    BufferedReader
    FileInputStream和FileReader
    Unable to instantiate receiver XXXXXX
    声明对象和定义数组
    Eclipse中文乱码问题
  • 原文地址:https://www.cnblogs.com/known/p/1440426.html
Copyright © 2011-2022 走看看