Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/code.quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Code Quality 🏆"
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main

jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "18.x"

- name: Install packages
working-directory: .
run: npm ci --legacy-peer-deps

- name: Build
working-directory: .
run: npm run build

- name: ESLint
working-directory: .
run: npm run lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
dist
examples
.DS_Store
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
# validate-form-fields
# Validate Form Fields
A lightweight, zero-dependency JavaScript/TypeScript library for validating form inputs with customisable rules. Supports length limits, alphanumeric enforcement, HTML blocking, and more.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Installation

To install the library, you can use npm or yarn:

```bash
npm install validate-form-fields
```

## Usage

Basic examples:

```React
import { ValidateFormFields } from 'validate-form-fields';

useEffect(() => {
const input = document.getElementById('name') as HTMLInputElement;
if (input){
ValidateFormFields.attachValidation(input, {
minLength: 3,
maxLength: 255,
allowAlphanumericOnly: true,
blockHTML: true,
requireNonEmpty: true,
});
}
}, []);
```

```JavaScript
import { ValidateFormFields } from 'validate-form-fields';

const input = document.getElementById('name');
if (input){
ValidateFormFields.attachValidation(input, {
minLength: 3,
maxLength: 255,
allowAlphanumericOnly: true,
blockHTML: true,
requireNonEmpty: true,
});
}

```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import globals from "globals";
import pluginJs from "@eslint/js";


/** @type {import('eslint').Linter.Config[]} */
export default [
{
languageOptions: {
ecmaVersion: 2020,
sourceType: "module",
globals: globals.browser,
}
},
pluginJs.configs.recommended,
];
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */

export default {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
};
Loading