validateInput
Validates a single input field, via its HTML attributes or an
explicit options override.
Returns: true \| Promise<unknown>
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
inputField | `string \ | HTMLInputElement` | required | - |
options | any | optional | {} | Overrides for the field’s validation rule (required, type, minLength, maxLength, pattern, message, etc.). Defaults to {}. |
callback | any | optional | - | Optional callback invoked with the result instead of/alongside the returned value. |
Usage
Example: Validate an Email Input Field
// Using with an input element
const inputElement = document.querySelector('input[type="email"]');
nfsfu234FormValidation.validateInput(inputElement, {
errorType: 'inline',
customErrorMessages: {
email: {
empty : 'Please enter an email address.',
formart : 'Please enter a valid email address.'
}
}
}).then(response => {
console.log(response);
});
// Using with an input element ID
nfsfu234FormValidation.validateInput('emailInputId', {
errorType: 'modal',
customErrorMessages: {
email: {
empty : 'Please enter an email address.',
formart : 'Please enter a valid email address.'
}
}
}).then(response => {
console.log(response);
});Last updated on