{"id":21524894,"url":"https://github.com/degjs/formvalidation-pattern","last_synced_at":"2025-10-29T15:38:55.072Z","repository":{"id":14366235,"uuid":"76422901","full_name":"DEGJS/formValidation-pattern","owner":"DEGJS","description":"A pattern rule for the DEGJS formValidation module.","archived":false,"fork":false,"pushed_at":"2023-01-05T23:35:07.000Z","size":586,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-04-14T22:12:27.119Z","etag":null,"topics":["forms"],"latest_commit_sha":null,"homepage":null,"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/DEGJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-14T03:52:37.000Z","updated_at":"2021-01-25T21:27:10.000Z","dependencies_parsed_at":"2023-01-13T17:54:38.784Z","dependency_job_id":null,"html_url":"https://github.com/DEGJS/formValidation-pattern","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DEGJS","download_url":"https://codeload.github.com/DEGJS/formValidation-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085010,"owners_count":20395523,"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":["forms"],"created_at":"2024-11-24T01:30:22.210Z","updated_at":"2025-10-29T15:38:54.965Z","avatar_url":"https://github.com/DEGJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# formValidation-pattern\n![Run Tests](https://github.com/DEGJS/formValidation-pattern/workflows/Run%20Tests/badge.svg)\n\nA pattern rule module for the DEGJS [formValidation](https://github.com/DEGJS/formValidation) module.\n\n\n## Install\nformValidation-pattern is an ES6 module. Consequently, you'll need an ES6 transpiler ([Babel](https://babeljs.io) is a nice one) as part of your Javascript workflow.\n\nIf you're already using NPM for your project, you can install formValidation-pattern with the following command:\n\n```\n$ npm install @degjs/form-validation-pattern\n```\n\n\n## Usage\nAfter importing, formValidation rule modules can be instantiated by passing an array of names into a formValidation options object:\n\n```js\nimport formValidation from \"@degjs/form-validation\";\n\n/* Import the Pattern rule module */\nimport pattern from \"@degjs/form-validation-pattern\";\n\nconst validationOptions = {\n    rules: [\n        pattern\n    ]\n};\n\n/* Instantiate the formValidation module on an element */\nconst formElement = document.querySelector('.form');\nconst validationInst = formValidation(formElement, validationOptions);\n```\n\nOptionally, default rule settings can be overridden by instantiating the rule as a function and passing options as an object: \n```js\nconst validationOptions = {\n    rules: [\n        pattern({\n        \tmessage: 'This message will override the default rule message.',\n            events: [\n                'focusout',\n                'submit'\n            ]\n        })\n    ]\n};\n```\n\nformValidation-pattern builds upon the HTML5 `pattern` validation pattern. Therefore, after instantiating the rule module, a field in the validation instance will be tested by this rule simply by adding a `pattern` attribute to the field input.\n\nThis rule module contains its own default validation message. However, this message can be overridden by adding a data attribute at the field or form level (in that order of importance).\n\nSample Markup:\n```html\n\u003cform class=\"form\" data-validation-pattern-message=\"This message will override the default rule message.\"\u003e\n    \u003cfieldset\u003e\n        \u003cdiv class=\"js-validation-field\" data-validation-pattern-message=\"This message will override both the default rule message and the form element message.\"\u003e\n            \u003clabel for=\"country\"\u003eThree-letter Country Code\u003c/label\u003e\n            \u003cinput type=\"text\" pattern=\"[A-Za-z]{3}\" id=\"country\" name=\"country\"\u003e\n        \u003c/div\u003e\n        \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n    \u003c/fieldset\u003e\n\u003c/form\u003e\n```\n\n\n## Options\n\n#### options.message\nType: `String`  \nDefault: `Please match the field format.`  \nThe default message displayed when a field fails this rule's validation test.\n\n#### options.messageAttr\nType: `String`  \nDefault: `data-validation-pattern-message`  \nThe data attribute formValidation will check when determining [message hierarchy](https://github.com/DEGJS/formValidation#configuring-error-messages)\n\n#### options.events\nType: `Array`  \nDefault: `['focusout','submit']`  \nAn array of DOM events that will cause the rule to run validation on a field (or the entire form, when using `submit`). NOTE: `focusout` should be used in place of `blur` due to event bubbling limitations.\n\nFor more detailed usage instructions, see the [formValidation Usage](https://github.com/DEGJS/formValidation#usage) documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Fformvalidation-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdegjs%2Fformvalidation-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Fformvalidation-pattern/lists"}