Code Monkey home page Code Monkey logo

jquery-checkform's Introduction

checkForm

基于jQuery的表单校验插件

Usage

<script type="text/javascript">
    $.checkFormSetup({e: 'Please input the text.'});
    
    $("#form").checkForm({
        '#username': {w: 'Input the wrong username.', r: /^[a-zA-Z]\w{4,15}$/},
        '#email': {e: 'Please input the email.', w: 'Input the wrong email.', r: 'email', t: 'next'},
        'input:radio': {e: 'Please select the sex.', t: '#sexTips', type: 'radio'},
        'input:checkbox': {e: 'Please select the hobbies.', w: 'Select the wrong hobbies.', r: /^1$/, t: '#hobbiesTips', type: 'checkbox'},
        'select': {e: 'Please select the profession.', type: 'select'},
    });
</script>

Regular

插件内置了一些常用的正则表达式。

  • int: 整数正则表达式
  • date: 日期正则表达式(格式:2013-03-22)
  • datetime: 时间正则表达式(格式:2013-03-22 16:22)
  • idcard: 身份证正则表达式
  • phone: 手机正则表达式
  • email: 邮箱正则表达式
  • url: 链接正则表达式
  • qq: QQ正则表达式
  • chinese: 中文正则表达式

Default

可用通过设置全局属性来每个校验设置默认值。

$.checkFormSetup({e: 'Please input the text.'});

属性如下:

  • e: 输入值为空提示语
  • w: 输入值错误提示语
  • r: 输入值校验正则表达式
  • t: 提示节点选择符(可写nextprev获取输入元素的相邻节点或者通过$(seletor)获取节点,默认:next
  • type: 校验通过时提示节点的类名(可选textselectradiocheckbox,默认:text
  • cpass: 校验通过时提示节点的类名(默认:check-pass
  • cerror: 校验失败时提示节点的类名(默认:check-error

Author

Travis

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.