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
To install the library, you can use npm or yarn:
npm install validation-form-fields
Basic examples:
import { ValidationFormFields } from 'validation-form-fields';
useEffect(() => {
const input = document.getElementById('name') as HTMLInputElement;
if (input){
ValidationFormFields.attachValidation(input, {
minLength: 3,
maxLength: 255,
allowAlphanumericOnly: true,
blockHTML: true,
requireNonEmpty: true,
});
}
}, []);
import { ValidationFormFields } from 'validation-form-fields';
const input = document.getElementById('name');
if (input){
ValidationFormFields.attachValidation(input, {
minLength: 3,
maxLength: 255,
allowAlphanumericOnly: true,
blockHTML: true,
requireNonEmpty: true,
});
}
This project is licensed under the MIT License. See the LICENSE file for more details.