Form input validation module
- Source:
(require("formValidation"))(config) → {String}
Set up event listeners for form validation
Parameters:
Name | Type | Description |
---|---|---|
config |
Array.<FormValidationConfig> |
configuration for setup |
- Source:
Requires
Methods
(inner) validateAge(el, item) → {HTMLElement}
Callback for validating age input. Adds 'invalid' class to DOM element if input is invalid or removes if valid.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement |
DOM element |
item |
FormValidationConfig |
Current element's validation configuration |
- Source:
Requires:
(inner) validateMatch(el, item) → {HTMLElement}
Callback for validating input against a regular expression. Adds 'invalid' class to DOM element if input is invalid, otherwise removes 'invalid' class.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement |
DOM element |
item |
FormValidationConfig |
Current element's validation configuration |
- Source:
(inner) validateRange(el, item) → {HTMLElement}
Callback for validating numerical input with defined minimum and maximum. Adds 'invalid' class to DOM element if input is invalid, otherwise removes 'invalid' class.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement |
DOM element |
item |
FormValidationConfig |
Current element's validation configuration |
- Source:
(inner) validateTime(el, item) → {HTMLElement}
Callback for validating time input. Adds 'invalid' class to DOM element if input is invalid. If valid, replaces input value with correctly formatted time input string and removes 'invalid' class.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement |
DOM element |
item |
FormValidationConfig |
Current element's validation configuration |
- Source:
Requires:
Type Definitions
FormValidationConfig :Object
Form validation configuration parameters. Must have either an inputType, a 'match' property, or a 'min' and 'max' property
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
String |
jQuery selector of inputs to validate |
|
min |
Number |
<optional> |
Minimum valid numeric input |
max |
Number |
<optional> |
Maximum valid numeric input |
match |
RegExp |
<optional> |
Regular expression that matches valid input |
inputType |
String |
<optional> |
Type of input if not a match or min/max validation |
- Source: