javascript-form-validator
Very small form validator.
Usage
Create a form and add fields insite div
tags. You can add div
tags with
data-error
right next to the input to display error messages.
options.regexes
An object of regexes to validate all the inputs.
options.errors
An object of error messages to show when inputs are invalid. There is a default
value which is displayed when no options.errors
matches with
input[data-validation]
and no input[data-validation-error-msg]
is present.
options.onFormValidate
This callback is called whenever an input is validated.
input[data-validation]
If this attribute is present validation is activated on the input. You can either set an empty value or a value that corresponds with the regexes and errors option on the validator.
input[data-validation-regex]
The regex that checks validation of the input. Use options.regexes
for
global settings.
input[data-validation-error-msg]
The error message shown in the div[data-error]
. Use options.errors
for
global settings.
HTML:
Required: Required Email Address: Required Phone Number: Submit
Javascript:
const validator = errors: {} // List of error messages that correspond with data-validation regexes: {} // List of regexes that correspond with data-validation { formdisabled = !isFormValid } // Callback that is called whenever a field is validatedvalidator