Giter Club home page Giter Club logo

palid's Introduction

Palid

Client-Side Javascript Validation

Demo

更多实例可以参考demo,也可以直接双击运行页面docs/index.html查看效果。

特性

  1. 支持ajax、settimeout等延时验证
  2. 支持类input、select、checkbox控件的验证
  3. 支持链式验证,支持控制路径上的每一个验证节点/状态
  4. 支持自定义验证规则
  5. 支持顺序验证和同时验证

安装

npm install palid

使用

import V from 'palid'

V('input')
    .notEmpty()
    .match('integer','请输入整数')
    .done(function(s) {
        console.log(s);
    });
        
V('input[name="num"]')
    .notEmpty('num不能为空')
    .match('integer','请输入整数')
    .range(-100, 200, '#{input}不在(#{$0}~#{$1})内')
    .done('ok');

var check = V('input[name="hobbies"]')
  .notEmpty()
  .range(1, 2, '已选择#{select}个(值为#{input}),请至少选择#{$0}个,最多选择#{$1}个');
check.done('ok');

当且仅当执行done()时才进行验证

另外,还要在控件的同层插入一个class="msg"的dom,用于显示验证结果信息。

<input id="age" type="text">
<span class="msg"></span>

还可以对显示效果个性化设置

.msg.fail {
    color: #f44336;
}
.msg.ok {
    color: #4CAF50;
}

palid's People

Contributors

bili avatar bilipan avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.