A lightweight form validation library for the browser.
- Simple API for form validation
- Built-in validation for standard HTML5 form validation attributes
- Custom validation messages
- Custom validators
- Accessibility features
- Written in TypeScript
- Pretty good test coverage
import { ValidMate } from 'valid-mate';
const form = document.querySelector('form');
const validation = new ValidMate(form);
Validates all inputs in the form. Shows error messages for any invalid inputs.
Validates a single input element. Shows an error message if invalid.
Returns true
if valid, false
if invalid.
Adds a custom validator that can be used to validate inputs. The validator object should have:
name
: String identifier for the validator; this must match a data attribute on the input element(s) you want to validatevalidate
: Function that takes an input element and returns booleanmessage
: Error message to show if validation fails