html5 form validator,GitHub - devniz/jsFormValidator: Modern JavaScript Form validator

jsFormValidator

jsFormValidator is a modern JavaScript Form validator

Validate any HTML form in 3 deadly simple steps:

1) Download and add into your index.html jQuery and jsFormValidator:

jsFormValidator Demo

jsFormValidator.App.create().Validator.applyRules('Login');

2) Let's say for instance we want to validate a basic login form. Create a 'Login' folder inside models/forms which also will contain rules.json

//Structure of your project using jsFormValidator

- myApp

-- models

--- forms

---- Login

----- rules.json

- jquery.min.js

- jsform.min.js

- index.html

//rules.json file containing a simple JSON object describing your validation rules.

{

"email": {

"validEmail":true,

"required":true

},

"username": {

"minLength":5,

"maxLength":15

},

"password": {

"validPassword":true,

"match": "password",

"required":true

}

}

3) Validate your form with one single line of code and check what's happen in your browser console!

jsFormValidator.App.create().Validator.applyRules('Login'); //Magic!

That's All Folks!

Notes

You need to keep the structure of the folder models/forms where the rules.json file should be. It doesn't matter how you setup jsForm and where you use it as it is a global object, but the models folder should always be at the root of your application. The JSON file 'rules.json' must be valid in each of your form validation folder (Login or whatever other name) and must keep the same name i.e rules.json. Make sure to pass the right name of your folder as a parameters to the function applyRules(nameOfYourRuleFolder). Inside your rules.json file, you HAVE to match each input field name with related rule.

Rules

required: Make sure that the field is provided by the user.

match: Make sure that the field match exactly another one.

email: Validate an email address.

password: Check the strenght of the password.

minlength: A field is limited to x minimum of characters.

maxLength: A field is limited to z maximum of characters

TODO

Add more validators

Add testing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值