All Projects → Knockout-Contrib → Knockout Validation

Knockout-Contrib / Knockout Validation

A validation library for Knockout JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Knockout Validation

definition
Simple and composable validation and coercion of data structures
Stars: ✭ 15 (-98.55%)
Mutual labels:  validation-library
vue-use-form
✅ A Vue.js composition API function to validate forms
Stars: ✭ 97 (-90.59%)
Mutual labels:  validation-library
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (-67.6%)
Mutual labels:  validation-library
whitelister
Simple, basic filtering and validation tool for Node.js.
Stars: ✭ 46 (-95.54%)
Mutual labels:  validation-library
oval
OVal - the object validation framework for Java
Stars: ✭ 95 (-90.79%)
Mutual labels:  validation-library
thai-citizen-id-validator
🦉 Validate Thai Citizen ID with 0 dependencies 🇹🇭
Stars: ✭ 35 (-96.61%)
Mutual labels:  validation-library
national-code
Simple implementation of Iranian national code validation
Stars: ✭ 31 (-96.99%)
Mutual labels:  validation-library
Govalidator
[Go] Package of validators and sanitizers for strings, numerics, slices and structs
Stars: ✭ 5,163 (+400.78%)
Mutual labels:  validation-library
beJS
Simple, light-weight assertions framework for javascript
Stars: ✭ 12 (-98.84%)
Mutual labels:  validation-library
Easyvalidation
✔️ A text and input validation library in Kotlin for Android
Stars: ✭ 328 (-68.19%)
Mutual labels:  validation-library
jsbb
JavaScript building blocks
Stars: ✭ 31 (-96.99%)
Mutual labels:  validation-library
form-validation
FormValidation, the best validation library for JavaScript
Stars: ✭ 137 (-86.71%)
Mutual labels:  validation-library
validate-polish
Utility library for validation of PESEL, NIP, REGON, identity card etc. Aimed mostly at Polish enviroment. [Polish] Walidacja numerów pesel, nip, regon, dowodu osobistego.
Stars: ✭ 31 (-96.99%)
Mutual labels:  validation-library
vayder
Easy and concise validations for Express routes
Stars: ✭ 26 (-97.48%)
Mutual labels:  validation-library
Data Binding Validator
Android fields validation library based on data binding adapters.
Stars: ✭ 345 (-66.54%)
Mutual labels:  validation-library
volder
volder is powerful Object schema validation lets you describe your data using a simple and readable schema and transform a value to match the requirements
Stars: ✭ 106 (-89.72%)
Mutual labels:  validation-library
valify
Validates data in JavaScript in a very simple way
Stars: ✭ 13 (-98.74%)
Mutual labels:  validation-library
Laravel Vue Validator
Simple package to display error in vue from laravel validation
Stars: ✭ 32 (-96.9%)
Mutual labels:  validation-library
Tld.js
JavaScript API to work easily with complex domain names, subdomains and well-known TLDs.
Stars: ✭ 399 (-61.3%)
Mutual labels:  validation-library
Valiktor
Valiktor is a type-safe, powerful and extensible fluent DSL to validate objects in Kotlin
Stars: ✭ 267 (-74.1%)
Mutual labels:  validation-library

Knockout Validation

A KnockoutJS Plugin for model and property validation

Build Status Build status Bower version npm version NuGet version

Contributors:

License: MIT

Install

Bower

bower install knockout-validation --save

NuGet

PM> Install-Package Knockout.Validation

NPM

npm install knockout.validation --save

CDN

cdnjs
jsdelivr

Getting Started

//start using it!
var myValue = ko.observable().extend({ required: true });

//oooh complexity
var myComplexValue = ko.observable().extend({
                     required: true,
                     minLength: 3,
                     pattern: {
                          message: 'Hey this doesnt match my pattern',
                          params: '^[A-Z0-9].$'
                     }
                 });

//or chaining if you like that
var myComplexValue = ko.observable()

myComplexValue.extend({ required: true })
            .extend({ minLength: 3 })
            .extend({ pattern: {
                 message: 'Hey this doesnt match my pattern',
                 params: '^[A-Z0-9].$'
            }});

//want to know if all of your ViewModel's properties are valid?
var myViewModel = ko.validatedObservable({
   property1: ko.observable().extend({ required: true }),
   property2: ko.observable().extend({ max: 10 })
});

console.log(myViewModel.isValid()); //false

myViewModel().property1('something');
myViewModel().property2(9);

console.log(myViewModel.isValid()); //true

see more examples on the Fiddle: http://jsfiddle.net/KHFn8/5424/

Native Validation Rules

Required:

var myObj = ko.observable('').extend({ required: true });

Min:

var myObj = ko.observable('').extend({ min: 2 });

Max:

var myObj = ko.observable('').extend({ max: 99 });

MinLength:

var myObj = ko.observable('').extend({ minLength: 3 });

MaxLength:

var myObj = ko.observable('').extend({ maxLength: 12 });

Email:

var myObj = ko.observable('').extend({ email: true });

... and MANY MORE

Much thanks to the jQuery Validation Plug-In team for their work on many of the rules

Custom Validation Rules

Custom Rules

Custom Rules can be created using the simple example below. All you need is to define a validator function and a default message. The validator function takes in the observable's value, and the params that you pass in with the extend method.

ko.validation.rules['mustEqual'] = {
    validator: function (val, params) {
        return val === params;
    },
    message: 'The field must equal {0}'
};
ko.validation.registerExtenders();

//the value '5' is the second arg ('params') that is passed to the validator
var myCustomObj = ko.observable().extend({ mustEqual: 5 });

Learn more about Custom Rules on the WIKI

Or Check out our User-Contributed Custom Rules!

HTML5 Validation Attributes

Required:

<input type="text" data-bind="value: myProp" required />

Min:

<input type="number" data-bind="value: myProp" min="2" />
<input type="week" data-bind="value:myWeek" min="2012-W03" />
<input type="month" data-bind="value:myMonth" min="2012-08" />

Max:

<input type="number" data-bind="value: myProp" max="99" />
<input type="week" data-bind="value:myWeek" max="2010-W15" />
<input type="month" data-bind="value:myMonth" min="2012-08" />

Pattern:

<input type="text" data-bind="value: myProp" pattern="^[a-z0-9].*" />

Step:

<input type="text" data-bind="value: myProp" step="3" />

Special Note, the 'MinLength' attribute was removed until the HTML5 spec fully supports it

Knockout Bindings

ValidationMessage

If you want to customize the display of your objects validation message, use the validationMessage binding:

<div>
   <input type="text" data-bind="value: someValue"/>
   <p data-bind="validationMessage: someValue"></p>
<div>

Check out more on Validation Bindings

Remote Validation Rules

Check out our Async Validation and jQuery AJAX Validation

Localization

Add a reference to the localization js files after the Knockout Validation plugin

<script type="text/javascript" src="knockout.validation.js"></script>
<script type="text/javascript" src="el-GR.js"></script>
<script type="text/javascript" src="fr-FR.js"></script>
<script type="text/javascript" src="de-DE.js"></script>

Apply localized messages

ko.validation.locale('el-GR');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].