{"id":13804106,"url":"https://github.com/Knockout-Contrib/Knockout-Validation","last_synced_at":"2025-05-13T17:31:17.701Z","repository":{"id":65263967,"uuid":"2639201","full_name":"Knockout-Contrib/Knockout-Validation","owner":"Knockout-Contrib","description":"A validation library for Knockout JS","archived":false,"fork":false,"pushed_at":"2022-07-27T14:27:26.000Z","size":1632,"stargazers_count":1020,"open_issues_count":137,"forks_count":373,"subscribers_count":71,"default_branch":"master","last_synced_at":"2025-05-05T07:42:28.353Z","etag":null,"topics":["javascript","knockout-validation","knockoutjs","knockoutjs-plugin","validation-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Knockout-Contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-10-24T21:03:14.000Z","updated_at":"2025-03-21T00:51:16.000Z","dependencies_parsed_at":"2023-01-16T15:00:43.016Z","dependency_job_id":null,"html_url":"https://github.com/Knockout-Contrib/Knockout-Validation","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Knockout-Contrib%2FKnockout-Validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Knockout-Contrib%2FKnockout-Validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Knockout-Contrib%2FKnockout-Validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Knockout-Contrib%2FKnockout-Validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Knockout-Contrib","download_url":"https://codeload.github.com/Knockout-Contrib/Knockout-Validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252934539,"owners_count":21827727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","knockout-validation","knockoutjs","knockoutjs-plugin","validation-library"],"created_at":"2024-08-04T01:00:41.881Z","updated_at":"2025-05-13T17:31:17.346Z","avatar_url":"https://github.com/Knockout-Contrib.png","language":"JavaScript","readme":"# Knockout Validation\nA KnockoutJS Plugin for model and property validation\n\n[![Build Status](https://travis-ci.org/Knockout-Contrib/Knockout-Validation.svg)](https://travis-ci.org/Knockout-Contrib/Knockout-Validation)\n[![Build status](https://ci.appveyor.com/api/projects/status/rmas31qgmi07wypi/branch/master?svg=true)](https://ci.appveyor.com/project/crissdev/knockout-validation/branch/master)\n[![Bower version](https://badge.fury.io/bo/knockout-validation.svg)](http://badge.fury.io/bo/knockout-validation)\n[![npm version](https://badge.fury.io/js/knockout.validation.svg)](http://badge.fury.io/js/knockout.validation)\n[![NuGet version](https://badge.fury.io/nu/Knockout.Validation.svg)](http://badge.fury.io/nu/Knockout.Validation)\n\nContributors:\n\n* [Eric Barnard](https://github.com/ericmbarnard)\n* [Steve Greatrex](https://github.com/stevegreatrex)\n* [Cristian Trifan](https://github.com/crissdev)\n* [Andy Booth](https://github.com/andybooth)\n* [Michal Poreba](https://github.com/michalporeba)\n* and many others!\n\nLicense: [MIT](http://www.opensource.org/licenses/mit-license.php)\n\n\n## Install\n\n#### Bower\n\n```sh\nbower install knockout-validation --save\n```\n\n#### NuGet\n\n```ps1\nPM\u003e Install-Package Knockout.Validation\n```\n\n#### NPM\n\n```sh\nnpm install knockout.validation --save\n```\n\n#### CDN\n\n##### [cdnjs](https://cdnjs.com/libraries/knockout-validation)\n* https://cdnjs.cloudflare.com/ajax/libs/knockout-validation/2.0.4/knockout.validation.js\n* https://cdnjs.cloudflare.com/ajax/libs/knockout-validation/2.0.4/knockout.validation.min.js\n\n##### [jsdelivr](http://www.jsdelivr.com/#!knockout.validation)\n- https://cdn.jsdelivr.net/npm/knockout.validation@2.0.4/dist/knockout.validation.js\n- https://cdn.jsdelivr.net/npm/knockout.validation@2.0.4/dist/knockout.validation.min.js\n\n\n## Getting Started\n```javascript\n//start using it!\nvar myValue = ko.observable().extend({ required: true });\n\n//oooh complexity\nvar myComplexValue = ko.observable().extend({\n                     required: true,\n                     minLength: 3,\n                     pattern: {\n                          message: 'Hey this doesnt match my pattern',\n                          params: '^[A-Z0-9].$'\n                     }\n                 });\n\n//or chaining if you like that\nvar myComplexValue = ko.observable()\n\nmyComplexValue.extend({ required: true })\n            .extend({ minLength: 3 })\n            .extend({ pattern: {\n                 message: 'Hey this doesnt match my pattern',\n                 params: '^[A-Z0-9].$'\n            }});\n\n//want to know if all of your ViewModel's properties are valid?\nvar myViewModel = ko.validatedObservable({\n   property1: ko.observable().extend({ required: true }),\n   property2: ko.observable().extend({ max: 10 })\n});\n\nconsole.log(myViewModel.isValid()); //false\n\nmyViewModel().property1('something');\nmyViewModel().property2(9);\n\nconsole.log(myViewModel.isValid()); //true\n\n```\nsee more examples on the Fiddle: http://jsfiddle.net/KHFn8/5424/\n\n## Native Validation Rules\n**Required**:\n\n```javascript\nvar myObj = ko.observable('').extend({ required: true });\n```\n**Min**:\n\n```javascript\nvar myObj = ko.observable('').extend({ min: 2 });\n```\n**Max**:\n\n```javascript\nvar myObj = ko.observable('').extend({ max: 99 });\n```\n**MinLength**:\n\n```javascript\nvar myObj = ko.observable('').extend({ minLength: 3 });\n```\n**MaxLength**:\n\n```javascript\nvar myObj = ko.observable('').extend({ maxLength: 12 });\n```\n**Email**:\n\n```javascript\nvar myObj = ko.observable('').extend({ email: true });\n```\n\n... and [MANY MORE](https://github.com/Knockout-Contrib/Knockout-Validation/wiki/Native-Rules)\n\n_Much thanks to the [jQuery Validation Plug-In](https://github.com/jzaefferer/jquery-validation) team for their work on many of the rules_\n## Custom Validation Rules\n#### Custom Rules\nCustom Rules can be created using the simple example below. All you need is to define a validator function and a default message.\nThe validator function takes in the observable's value, and the `params` that you pass in with the `extend` method.\n\n```javascript\nko.validation.rules['mustEqual'] = {\n    validator: function (val, params) {\n        return val === params;\n    },\n    message: 'The field must equal {0}'\n};\nko.validation.registerExtenders();\n\n//the value '5' is the second arg ('params') that is passed to the validator\nvar myCustomObj = ko.observable().extend({ mustEqual: 5 });\n```\nLearn more about Custom Rules on the [WIKI](https://github.com/Knockout-Contrib/Knockout-Validation/wiki/Custom-Validation-Rules)\n\n**Or Check out our [User-Contributed Custom Rules](https://github.com/Knockout-Contrib/Knockout-Validation/wiki/User-Contributed-Rules)!**\n\n## HTML5 Validation Attributes\n\n**Required**:\n\n```html\n\u003cinput type=\"text\" data-bind=\"value: myProp\" required /\u003e\n```\n\n**Min**:\n\n```html\n\u003cinput type=\"number\" data-bind=\"value: myProp\" min=\"2\" /\u003e\n\u003cinput type=\"week\" data-bind=\"value:myWeek\" min=\"2012-W03\" /\u003e\n\u003cinput type=\"month\" data-bind=\"value:myMonth\" min=\"2012-08\" /\u003e\n```\n\n**Max**:\n\n```html\n\u003cinput type=\"number\" data-bind=\"value: myProp\" max=\"99\" /\u003e\n\u003cinput type=\"week\" data-bind=\"value:myWeek\" max=\"2010-W15\" /\u003e\n\u003cinput type=\"month\" data-bind=\"value:myMonth\" min=\"2012-08\" /\u003e\n```\n\n**Pattern**:\n\n```html\n\u003cinput type=\"text\" data-bind=\"value: myProp\" pattern=\"^[a-z0-9].*\" /\u003e\n```\n\n**Step**:\n\n```html\n\u003cinput type=\"text\" data-bind=\"value: myProp\" step=\"3\" /\u003e\n```\n**Special Note, the 'MinLength' attribute was removed until the HTML5 spec fully supports it**\n\n## Knockout Bindings\n\n### ValidationMessage\nIf you want to customize the display of your objects validation message, use the `validationMessage` binding:\n\n```html\n\u003cdiv\u003e\n   \u003cinput type=\"text\" data-bind=\"value: someValue\"/\u003e\n   \u003cp data-bind=\"validationMessage: someValue\"\u003e\u003c/p\u003e\n\u003cdiv\u003e\n```\nCheck out more on [Validation Bindings](https://github.com/Knockout-Contrib/Knockout-Validation/wiki/Validation-Bindings)\n\n## Remote Validation Rules\nCheck out our [Async Validation](https://github.com/Knockout-Contrib/Knockout-Validation/wiki/Async-Rules) and [jQuery AJAX Validation](https://github.com/ericmbarnard/Knockout-Validation/wiki/Async-Rules)\n\n## Localization\n\nAdd a reference to the localization js files after the Knockout Validation plugin\n\n```html\n\u003cscript type=\"text/javascript\" src=\"knockout.validation.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"el-GR.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"fr-FR.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"de-DE.js\"\u003e\u003c/script\u003e\n```\n\nApply localized messages\n\n```js\nko.validation.locale('el-GR');\n```\n","funding_links":[],"categories":["Plugins and libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnockout-Contrib%2FKnockout-Validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKnockout-Contrib%2FKnockout-Validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnockout-Contrib%2FKnockout-Validation/lists"}