Validate
The validate function is used to validate a form. When you call this function, it will automatically validate the form based on the specified rules and return the validation result.
Works in: HTML5, React JS
| Parameter | Type | Default | Description |
|---|---|---|---|
userOptions | HTMLFormElement | HTMLDivElement | string | { form: HTMLFormElement | HTMLDivElement | string; customErrorMessages?: any[] } | undefined | Options for the form validation. Can be a string (ID of the form), an HTMLFormElement, an HTMLDivElement, or an object containing form and custom error messages. |
callback | function | undefined | Optional callback function to execute after form validation. Receives an error message object as its parameter. |
Usage
Option 1.
const myForm = document.getElementById("myForm")
nfsfu234FormValidation.validate(form)
.then((response) => {
const { message, type, data } = response;
console.log(response);
});Option 2.
const myForm = document.getElementById("myForm");
nfsfu234FormValidation.validate(myForm, (response) => {
const { message, type, data } = response;
console.log(response);
});See also
Last updated on