{"id":20531966,"url":"https://github.com/repocrypts/validator","last_synced_at":"2025-04-14T06:21:57.252Z","repository":{"id":34564141,"uuid":"61971682","full_name":"repocrypts/Validator","owner":"repocrypts","description":"Client-side javascript validator library ports from Laravel 5.2","archived":false,"fork":false,"pushed_at":"2024-03-10T20:50:17.000Z","size":1000,"stargazers_count":46,"open_issues_count":11,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T20:07:26.087Z","etag":null,"topics":["javascript","laravel","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/repocrypts.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-26T03:14:58.000Z","updated_at":"2024-02-20T23:24:20.000Z","dependencies_parsed_at":"2024-06-18T16:49:59.267Z","dependency_job_id":"505d3ac5-2b4d-4e74-9ef2-bd7a28065fe3","html_url":"https://github.com/repocrypts/Validator","commit_stats":null,"previous_names":["repocrypts/validator","jfstn/validator"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repocrypts%2FValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repocrypts%2FValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repocrypts%2FValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repocrypts%2FValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/repocrypts","download_url":"https://codeload.github.com/repocrypts/Validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830903,"owners_count":21168368,"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","laravel","validation","validator"],"created_at":"2024-11-16T00:11:28.786Z","updated_at":"2025-04-14T06:21:57.200Z","avatar_url":"https://github.com/repocrypts.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validator\n\n[![npm](https://img.shields.io/npm/v/Validator.svg)](https://www.npmjs.com/package/Validator)\n[![Travis build](https://img.shields.io/travis/jfstn/Validator.svg)](https://travis-ci.org/jfstn/Validator)\n[![Coverage Status](https://coveralls.io/repos/github/jfstn/Validator/badge.svg?branch=master)](https://coveralls.io/github/jfstn/Validator?branch=master)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjfstn%2FValidator.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjfstn%2FValidator?ref=badge_shield)\n\nA client-side JavaScript validation package, based on Laravel 5.2 validation.\n\n## Installation\n\n1.  Included as global `\u003cscript\u003e`, copy the `Validator.js` file inside `dist` directory to your project directory\n    and reference it in the script tag. Or, you can use NPMCDN to reference it like so,\n\n    ```html\n    \u003chead\u003e\n        \u003cscript src=\"public/js/Validator.js\"\u003e\u003c/script\u003e\n        \u003c!-- or using NPMCDN --\u003e\n        \u003cscript src=\"https://unpkg.com/Validator\"\u003e\u003c/script\u003e\n    \u003c/head\u003e\n    ```\n\n2.  Using NPM\n    ```bash\n    npm install Validator --save\n    ```\n    ```javascript\n    const Validator = require('Validator');\n    ```\n\n## Usage\n\n-   Basic usage\n\n    ```javascript\n    const data = {\n        name: 'John Doe',\n        company: 'Example Co.',\n        birthday: '1985-04-16'\n    };\n\n    const rules = {\n        name: 'required',\n        // for multiple rules\n        birthday: 'required|date', // can be a piped string\n        company: ['required', 'string'] // can be an array of strings\n    };\n\n    const v = Validator.make(data, rules);\n\n    if (v.fails()) {\n        const errors = v.getErrors();\n        console.log(errors);\n    }\n    ```\n\n    `getErrors()` will return an object containing error field as a key and array of error messages for that field.\n\n-   Custom Error Messages\n\n    ```javascript\n    const messages = {\n        // custom message for based rules\n        required: 'You forgot the :attr field',\n        email: ':attr is not valid',\n        // custom message for specific rule of attribute\n        'receiver.email': 'The receiver email address is not valid'\n    };\n\n    const v = Validator.make(data, rules, messages);\n\n    if (v.passes()) {\n        //...\n    }\n    ```\n\n-   Custom Name\n\n    ```javascript\n    const v = Validator.make(data, rules, messages, { email: 'Email Address' });\n    ```\n\n## Supported Validation Rules\n\nSee validation rule usage in [Laravel Documentation](https://laravel.com/docs/5.2/validation#available-validation-rules)\n\n-   accepted\n-   after (date)\n-   alpha\n-   alpha_num\n-   alpha_dash\n-   array\n-   before (date)\n-   between\n-   boolean\n-   confirmed\n-   date\n-   different\n-   digits\n-   digits_between\n-   email\n-   filled\n-   in\n-   integer\n-   ip\n-   json\n-   max\n-   min\n-   not_in\n-   numeric\n-   present\n-   regex\n-   required\n-   required_if\n-   required_unless\n-   required_with\n-   required_with_all\n-   required_without\n-   required_without_all\n-   same\n-   size\n-   string\n-   url\n\n## Extending with Custom Validation Rules\n\nThe validator can be extended with custom rules\n\n```javascript\nconst rules = {\n    id: 'required|mongoid'\n};\n\nfunction validateMongoId(name, value, params) {\n    let hexadecimal = /^[0-9A-F]+$/i;\n    return value \u0026\u0026 hexadecimal.test(value) \u0026\u0026 value.length === 24;\n}\n\nconst v = Validator.make(data, rules);\nv.extend('mongoid', validateMongoId, ':attr is not a valid mongo id');\n\nif (v.passes()) {\n    //...\n}\n```\n\n`validator.extend` takes three _required_ parameters:\n\n-   `name`: the name of the custom rule\n-   `callback`: called when the rule is checked\n-   `validationMessage`: error message text on validation failure\n\nThe validation callback receives three parameters:\n\n1. `name`: the field name being validated\n2. `value`: the given value in the data\n3. `params`: Any parameters, passed after the colon in the rule definition.\n\nParams defined ike so: `rulename:min=10,max=15` would be passed in as an array: `['min=10', 'max=15']`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepocrypts%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frepocrypts%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepocrypts%2Fvalidator/lists"}