{"id":16414760,"url":"https://github.com/amranich/form-validate-js","last_synced_at":"2025-08-22T10:39:43.272Z","repository":{"id":48333504,"uuid":"368579900","full_name":"AmraniCh/form-validate-js","owner":"AmraniCh","description":"Light and simple JavaScript form validation library with support of native HTML5 validation attributes and input types","archived":false,"fork":false,"pushed_at":"2022-12-05T10:50:13.000Z","size":102,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T22:41:34.366Z","etag":null,"topics":["form-validation","html5-validation","vanilla-javascript"],"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/AmraniCh.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":"2021-05-18T15:26:52.000Z","updated_at":"2024-11-22T20:36:27.000Z","dependencies_parsed_at":"2023-01-23T01:30:28.724Z","dependency_job_id":null,"html_url":"https://github.com/AmraniCh/form-validate-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmraniCh%2Fform-validate-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmraniCh%2Fform-validate-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmraniCh%2Fform-validate-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmraniCh%2Fform-validate-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmraniCh","download_url":"https://codeload.github.com/AmraniCh/form-validate-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238394323,"owners_count":19464583,"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":["form-validation","html5-validation","vanilla-javascript"],"created_at":"2024-10-11T06:54:56.821Z","updated_at":"2025-02-12T00:31:37.715Z","avatar_url":"https://github.com/AmraniCh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Form Validate JS\n\nLight and simple JavaScript form validation library with support of native HTML5 validation attributes and input types.\n\n## Simple usage example\n\n```javascript\nFormValidator('#myForm', {\n    events: ['submit', 'input'],\n    constraints: {\n        // specifies constraints for form fileds\n        username: {\n            required: true,\n            match: 'username',\n            maxlength: 30,\n        },\n        password: {\n            required: true,\n            match: /^[a-zA-Z0-9]*$/,\n            maxlength: function() {\n                // some logic\n                return 30,\n            },\n            messages: {\n                match: 'Accept only characters and numbers.',\n            },\n        },\n        confirm_password: {\n            required: true,\n            equal: '#password',\n        },\n    },\n    // optional\n    submitHandler: function () {\n        // handle manuallly the submitting of the form\n    },\n    // optional\n    invalidHandler: function () {\n        // get the form errors\n        console.log(this.errors);\n    },\n});\n```\n\n## Supported settings and their default values\n\n| Name       | description                                   | optional           | default value |\n| ---------- | --------------------------------------------- | ------------------ | ------------- |\n| events     | specifies the validation events in an array   | :heavy_check_mark: | ['submit']    |\n| lang       | specifies the error messages display language | :heavy_check_mark: | en            |\n| showErrors | whether to show error messages or not         | :heavy_check_mark: | true          |\n\n## Supported constraint types\n\n| Name      | description                                                                                                                                                   | Type                     |\n| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |\n| required  | requiring the field                                                                                                                                           | Boolean\\|Function        |\n| match     | The field value must match a regex, the value of this constraint can be either one of the regular expression defined by the library or a custom regex pattern | String\\|RegExp\\|Function |\n| maxlength | The field value cannot be greater than the giving value                                                                                                       | Number\\|Function         |\n| equal     | The field value must be the same to other field value                                                                                                         | String                   |\n\n**note : All the constraint types can accept a function value that must return the value needed for the constraint type.**\n\nExample :\n\n```javascript\nFormValidator('#myForm', {\n    constraints: {\n        username: {\n            maxlength: function () {\n                // logic\n                return length;\n            },\n        },\n    },\n});\n```\n\n## Supported regular expressions for the 'match' constraint type\n\n:heavy_check_mark: username \u003cbr\u003e\n:heavy_check_mark: email \u003cbr\u003e\n:heavy_check_mark: number \u003cbr\u003e\n\n## Supported languages for error messages\n\n:heavy_check_mark: English \u003cbr\u003e\n:heavy_check_mark: French \u003cbr\u003e\n\n## Error messages\n\nYou can specify and customize the error messages with the `messages` object, and this is two ways to do that.\n\n### Specify your own message\n\n```javascript\nusername: {\n    maxlength: 30,\n    messages: {\n        maxlength: \"username length cannot be greater than {0} characters.\"\n    }\n}\n```\n\n### Altering the default message\n\n```javascript\nusername: {\n    required: true,\n    messages: {\n        required: function(msg) {\n                return \"Error : \" + msg;\n        }\n    }\n}\n```\n\n## Override the default error messages\n\n```javascript\nvar validate = FormValidator('#myForm');\n\nvalidate.defaults.messages.en = {\n    custom: 'not match the regex pattern [{0}].',\n    email: '{0} is not a valid email address.',\n    username: '{0} is not valid username.',\n    number: '{0} is not valid number.',\n    required: 'required.',\n    maxlength: 'maximaux characters length is {0}.',\n    equal: 'not the same value.',\n};\n\n/**\n * Because the error messages sets when calling the FormValidator function \n * constructor we need to rebuild the constraints object to apply\n * the error messages tha we've just override above\n */\nvalidate.buildConstraints();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famranich%2Fform-validate-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famranich%2Fform-validate-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famranich%2Fform-validate-js/lists"}