Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.
v3 (current)validateInput

validateInput

Validates a single input field, via its HTML attributes or an explicit options override. Returns: true \| Promise<unknown>

ParameterTypeRequiredDefaultDescription
inputField`string \HTMLInputElement`required-
optionsanyoptional{}Overrides for the field’s validation rule (required, type, minLength, maxLength, pattern, message, etc.). Defaults to {}.
callbackanyoptional-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