Git Product home page Git Product logo

formformat's Introduction

表单验证

一款轻量级表单验证库; 不依赖任何框架和库。

例子

<input type="text">
<input type="button" value="提交">
<input type="checkbox">
// 可以打开html中的demo.html,将以下注释打开运行即可查看效果。
var inputs = document.getElementsByTagName('input');
inputs[1].onclick = function() {
    //验证是否为空
    //console.log( formFormat.isEmpty(inputs[0].value) );

    //字符长度限制2-5 (按字符串个数来计算)
    //console.log( formFormat.limitString(inputs[0].value, [2,5]) );

    //字符长度限制2-5 (按字符串字节来计算:英文占1字节,汉字占2字节)
    //console.log( formFormat.limitStr(inputs[0].value, [2,5], true, true) );

    //验证手机号码
    //console.log( formFormat.isMobile(inputs[0].value) );

    //验证固定电话
    //console.log( formFormat.isTelephone(inputs[0].value) );

    //验证电话号码(包括手机+固定电话)
    //console.log( formFormat.isPhone(inputs[0].value) );

    //验证邮箱
    //console.log( formFormat.isEmail(inputs[0].value) );

    //验证邮政编码
    //console.log( formFormat.isZipcode(inputs[0].value) );

    //验证身份证号码
    //console.log( formFormat.isIdcode(inputs[0].value) );

    //验证纯数字
    //console.log( formFormat.isNumber(inputs[0].value) );

    //限制数字大小范围
    //console.log( formFormat.limitNumder(inputs[0].value, [50,100]) );

    //验证纯英文
    //console.log( formFormat.isEng(inputs[0].value) );

    //验证含有英文
    //console.log( formFormat.hasEng(inputs[0].value) );

    //验证纯中文
    //console.log( formFormat.isCn(inputs[0].value) );

    //验证含有中文
    //console.log( formFormat.hasCn(inputs[0].value) );

    //验证字母、数字
    //console.log( formFormat.isEngNum(inputs[0].value) );

    //验证字母、数字和下划线
    //console.log( formFormat.isw(inputs[0].value) );

    //单个单选框或复选框是否选中
    //console.log( formFormat.isChecked(inputs[2]) );

    //验证网址
    //console.log( formFormat.isUrl(inputs[0].value) );
};

formformat's People

Contributors

jerry2359 avatar

Watchers

James Cloos avatar  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.