{"id":13778102,"url":"https://github.com/kelp404/angular-validator","last_synced_at":"2025-04-09T19:17:45.173Z","repository":{"id":11554085,"uuid":"14040010","full_name":"kelp404/angular-validator","owner":"kelp404","description":"AngularJS form validation.","archived":false,"fork":false,"pushed_at":"2018-03-10T09:44:11.000Z","size":289,"stargazers_count":162,"open_issues_count":21,"forks_count":46,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-09T19:17:39.695Z","etag":null,"topics":["angularjs","coffeescript"],"latest_commit_sha":null,"homepage":"http://kelp404.github.io/angular-validator/","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kelp404.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-01T09:49:37.000Z","updated_at":"2024-02-23T19:28:22.000Z","dependencies_parsed_at":"2022-09-08T12:20:58.563Z","dependency_job_id":null,"html_url":"https://github.com/kelp404/angular-validator","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelp404%2Fangular-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelp404%2Fangular-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelp404%2Fangular-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelp404%2Fangular-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelp404","download_url":"https://codeload.github.com/kelp404/angular-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094988,"owners_count":21046770,"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":["angularjs","coffeescript"],"created_at":"2024-08-03T18:00:51.236Z","updated_at":"2025-04-09T19:17:45.145Z","avatar_url":"https://github.com/kelp404.png","language":"CoffeeScript","funding_links":[],"categories":["Data Manage"],"sub_categories":[],"readme":"# angular-validator [![Build Status](https://secure.travis-ci.org/kelp404/angular-validator.png?branch=master)](http://travis-ci.org/kelp404/angular-validator) [![devDependency Status](https://david-dm.org/kelp404/angular-validator/dev-status.png?branch=master)](https://david-dm.org/kelp404/angular-validator#info=devDependencies)\n\n[MIT License](http://www.opensource.org/licenses/mit-license.php)  \n\n\nThis is an AngularJS form validation written in [CoffeeScript](http://coffeescript.org) and **thinking in AngularJS not jQuery**.\n\n\n## Installation\n**bower**\n```bash\n$ bower install https://github.com/kelp404/angular-validator.git\\#0.2.9 -S\n```\n\n\n## Frameworks\n1. [jQuery](https://jquery.com/) 3.3.1\n\n2. [AngularJS](http://angularjs.org/) 1.5.11\n\n3. [Bootstrap 3](http://getbootstrap.com/)\n\u003e If your `error` is `string` in rules you should include bootstrap3.css and use `form-group` to the input div.\n\n\n\n\n## $validator\n```coffee\nangular.module 'yourApp', ['validator']\n```\n#### register\n```coffee\n# .config\n$validatorProvider.register = (name, object={}) -\u003e\n    ###\n    Register the rule.\n    @params name: The rule name.\n    @params object:\n        invoke: 'watch' or 'blur' or undefined(validate by yourself)\n        init: function(scope, element, attrs, $injector)\n        validator: RegExp() or function(value, scope, element, attrs, $injector)\n        error: string or function(value, scope, element, attrs, $injector)\n        success: function(value, scope, element, attrs, $injector)\n    ###\n# .run\n$validator.register = (name, object={}) -\u003e\n```\n\n#### validate\n```coffee\n$validate.validate = (scope, model) =\u003e\n    ###\n    Validate the model.\n    @param scope: The scope.\n    @param model: The model name of the scope or validator-group.\n    @return:\n        @promise success(): The success function.\n        @promise error(): The error function.\n    ###\n```\n\n#### reset\n```coffee\n$validate.reset = (scope, model) =\u003e\n    ###\n    Reset validated error messages of the model.\n    @param scope: The scope.\n    @param model: The model name of the scope or validator-group.\n    ###\n```\n\n\n\n\n## validator.directive\n```coffee\na = angular.module 'validator.directive', ['validator.provider']\nvalidator = ($injector) -\u003e\n    restrict: 'A'\n    require: 'ngModel'\n    link: (scope, element, attrs) -\u003e\n        ###\n        The link of `validator`.\n        You could use `validator=[rule, rule]` or `validator=/^regex$/`.\n        ###\nvalidator.$inject = ['$injector']\na.directive 'validator', validator\n```\n\n#### validator=\"[rule, rule]\", [required], [validator-required=\"true/false\"], [validator-group=\"group\"]\n```html\n\u003cdiv class=\"form-group\"\u003e\n    \u003clabel for=\"required0\" class=\"col-md-2 control-label\"\u003eRequired\u003c/label\u003e\n    \u003cdiv class=\"col-md-10\"\u003e\n        \u003cinput type=\"text\" ng-model=\"formWatch.required\" validator=\"[required]\"\n         class=\"form-control\" id=\"required0\" placeholder=\"Required\"/\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n#### validator=\"/^regex$/\", [validator-error=\"msg\"], [validator-invoke=\"watch\"], [required], [validator-required=\"true/false\"], [validator-group=\"group\"]\n```html\n\u003cdiv class=\"form-group\"\u003e\n    \u003clabel for=\"regexp0\" class=\"col-md-2 control-label\"\u003eRegExp [a-z]\u003c/label\u003e\n    \u003cdiv class=\"col-md-10\"\u003e\n        \u003cinput type=\"text\" ng-model=\"formWatch.regexp\" validator=\"/[a-z]/\"\n         validator-invoke=\"watch\" validator-error=\"it should be /[a-z]/\"\n         class=\"form-control\" id=\"regexp0\" placeholder=\"RegExp [a-z]\"/\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n#### [required], [validator-required=\"true/false\"]\nIf the element has this attribute, $validator will add the rule `required` into rules of the element.\n\n\n\n\n## validator.rules\n```coffee\nangular.module 'yourApp', ['validator.rules']\n```\n\nThere are default rules in this module.\n+ required\n+ number\n+ email\n+ url\n\n\n\n\n## Example\n```html\n\u003c!-- Bootstrap3 (not required) --\u003e\n\u003clink type=\"text/css\" rel=\"stylesheet\" href=\"https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css\"/\u003e\n\u003c!-- jQuery --\u003e\n\u003cscript type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"\u003e\u003c/script\u003e\n\u003c!-- AngularJS --\u003e\n\u003cscript type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.5.11/angular.min.js\"\u003e\u003c/script\u003e\n\u003c!-- $validator --\u003e\n\u003cscript type=\"text/javascript\" src=\"dist/angular-validator.js\"\u003e\u003c/script\u003e\n\u003c!-- basic rules (not required) --\u003e\n\u003cscript type=\"text/javascript\" src=\"dist/angular-validator-rules.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- submit --\u003e\n\u003cdiv class=\"panel panel-default\"\u003e\n    \u003cdiv class=\"panel-heading\"\u003e\n        \u003ch3 class=\"panel-title\"\u003esubmit\u003c/h3\u003e\n    \u003c/div\u003e\n    \u003cform class=\"form-horizontal panel-body\"\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003clabel for=\"required2\" class=\"col-md-2 control-label\"\u003eRequired\u003c/label\u003e\n            \u003cdiv class=\"col-md-10\"\u003e\n                \u003cinput type=\"text\" ng-model=\"formSubmit.required\" validator=\"[requiredSubmit]\" class=\"form-control\" id=\"required2\" placeholder=\"Required\"/\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003clabel for=\"regexp2\" class=\"col-md-2 control-label\"\u003eRegExp [a-z]\u003c/label\u003e\n            \u003cdiv class=\"col-md-10\"\u003e\n                \u003cinput type=\"text\" ng-model=\"formSubmit.regexp\" validator=\"/[a-z]/\" validator-error=\"it should be /[a-z]/\" class=\"form-control\" id=\"regexp2\" placeholder=\"RegExp [a-z]\"/\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003clabel for=\"http2\" class=\"col-md-2 control-label\"\u003e$http\u003c/label\u003e\n            \u003cdiv class=\"col-md-10\"\u003e\n                \u003cinput type=\"text\" ng-model=\"formSubmit.http\" validator=\"[backendSubmit]\" class=\"form-control\" id=\"http2\" placeholder=\"do not use 'Kelp' or 'x'\"/\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003cdiv class=\"col-md-offset-2 col-md-10\"\u003e\n                \u003cinput type=\"submit\" ng-click=\"submit()\" class=\"btn btn-default\"/\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/form\u003e\n    \u003cdiv class=\"panel-footer\"\u003e{{formSubmit}}\u003c/div\u003e\n\u003c/div\u003e\n```\n\n```coffee\na = angular.module 'app', ['validator', 'validator.rules']\na.config ($validatorProvider) -\u003e    \n    $validatorProvider.register 'backendSubmit',\n        validator: (value, scope, element, attrs, $injector) -\u003e\n            $http = $injector.get '$http'\n            h = $http.get 'example/data.json'\n            h.then (data) -\u003e\n                if data and data.status \u003c 400 and data.data\n                    return no if value in (x.name for x in data.data)\n                    return yes\n                else\n                    return no\n        error: \"do not use 'Kelp' or 'x'\"\n    # submit - required\n    $validatorProvider.register 'requiredSubmit',\n        validator: RegExp \"^.+$\"\n        error: 'This field is required.'\n```\n\n```coffee\n# CoffeeScript\n# the form model\n$scope.formSubmit =\n    required: ''\n    regexp: ''\n    http: ''\n# the submit function\n$scope.submit = -\u003e\n    v = $validator.validate $scope, 'formSubmit'\n    v.success -\u003e\n        # validated success\n        console.log 'success'\n    v.error -\u003e\n        # validated error\n        console.log 'error'\n```\n\n```js\n// JavaScript\n// the form model\n$scope.formSubmit = {\n    required: '',\n    regexp: '',\n    http: ''\n};\n// the submit function\n$scope.submit = function () {\n    $validator.validate($scope, 'formSubmit')\n    .success(function () {\n        // validated success\n        console.log('success');\n    })\n    .error(function () {\n        // validated error\n        console.log('error');\n    });\n};\n```\n\n\n\n\n## Unit Test\n```bash\n$ grunt test\n```\n\n\n\n\n## Development\n```bash\n# install node modules\n$ npm install\n# install bower components\n$ bower install\n```\n```bash\n# run the local server and the file watcher to compile CoffeeScript\n$ grunt dev\n# compile coffee script and minify\n$ grunt build\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelp404%2Fangular-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelp404%2Fangular-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelp404%2Fangular-validator/lists"}