Namespace validanguage
Global validanguage object
The validanguage library was written by DrLongGhost in 2008. See attached MIT_License.js
and readme.txt for licensing and documentation. Visit http://www.drlongghost.com/ for updates.
Defined in: validanguage_uncompressed.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
The validanguage library was written by DrLongGhost in 2008.
|
| Field Attributes | Field Name and Description |
|---|---|
| <static> |
validanguage.useLibrary
Valid values are 'none', 'prototype', and 'scriptaculous'.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
validanguage.addEvent(Object, Event, Function)
Generic cross-browser addEvent() function.
|
| <static> |
validanguage.addEventInit()
Reassigns the validanguage.addEvent function, if an external library is being used.
|
| <static> |
validanguage.addOrCreateValidationWrapper(Form, eventType,, validationsCounter,)
This function wraps multiple validanguage.el.elemId.validations event handlers
and transformations within a single wrapper to call all loaded validations/transformations
and exit as soon as a validation returns false.
|
| <static> |
validanguage.addValidation(elemId, eventTypes, validationNames)
This function is used to either load a new validation for a form field, or to
reactivate a validation previously removed with the removeValidation() method.
|
| <static> |
validanguage.ajax(url, callback)
Very simple AJAX function
|
| <static> |
validanguage.ajaxInit()
Initializes validanguage.ajax as browser-specific
|
| <static> |
validanguage.concatCollection(obj1, obj2)
Combines 2 node lists into 1
|
| <static> |
validanguage.empty(testVar, falseIsEmpty)
Emulates PHP's empty() function.
|
| <static> |
validanguage.format(Pattern, String, Regular)
This is a preset transformation which is used to reformat text input
to match a desired pattern
|
| <static> |
validanguage.getCharCode(suppliedCharacter)
This function is one big ass switch case to look up a char code
for the supplied character
|
| <static> |
validanguage.getComments(el)
Fetches all comment nodes in the passed form node and returns them in a node list
Doesnt work in konqueror, since konqueror strips all comments from the DOM
|
| <static> |
validanguage.getDateTimeDefaultOptions(options, defaults)
Helper function used by validateDate() and validateTimestamp().
|
| <static> |
validanguage.getElSetting(Name, ID)
This function checks for a given setting in increasing specificity
within the validanguage.forms[formId].settings object, and within the passed
validanguage.el objects
|
| <static> |
validanguage.getFormSettings(id)
This function returns the validanguage.form[formId].setting object for the passed element ID
|
| <static> |
validanguage.getSettingFromComment(Name, Full)
This function parses the passed comment to retrieve the indicated setting
|
| <static> |
validanguage.hideError()
This function hides the div containing the validanguage error messages for
failed validations
|
| <static> |
validanguage.inArray(needle, haystack)
Determines whether the passed item is present in the array or object.
|
| <static> |
validanguage.inheritIfDefined(settingsHaystack, settingsNeedles, settingsTarget, constrainType)
This function searches settingsHaystack for all variables defined in the settingsNeedles
array, and if they are located, they are copied over to the settingsTarget
|
| <static> |
validanguage.init()
Initialization function for validanguage.
|
| <static> |
validanguage.insertAfter(nodeToAdd, referenceNode)
Function to insert 1 Node after another in the DOM.
|
| <static> |
validanguage.loadCommentAPI(For)
This function parses all comments in the current document, looking for
the comment-based API and converts any validanguage statements it
finds into the element/json-based API for further processing.
|
| <static> |
validanguage.loadElAPI()
This function parses the validanguage.el object to load all the
form-element-specific validation settings which the end user has defined
via the Object-based API
|
| <static> |
validanguage.parseSubstring(startChar, endChar, subject)
This function searches the passed subject and returns an Array of strings
which are delimited by the characters passed to the function in the
first 2 arguments.
|
| <static> |
validanguage.populate()
Main function to be called onload to load all the validations
|
| <static> |
validanguage.removeValidation(elemId, eventTypes, validationNames)
This function is used to deactivate a previously loaded validation.
|
| <static> |
validanguage.resolveArray(args, returnType, ignoreCommas)
This function accepts as input a function, a string, an array of
functions, an array of strings, or a comma-delimited list of functon
names as its argument and returns an Array of functions or strings
comprising the passed arguments.
|
| <static> |
validanguage.safeAlert(errorMsg)
This function shows an alert box and uses a counter to help prevent
infinite loops which can be created by the interaction between an alert()
statement and an onblur handler on an element.
|
| <static> |
validanguage.showError(Text)
This function shows the error messages for failed validations by dynamically
creating a div
|
| <static> |
validanguage.showSubmitMessage(validationResult, failedValidations)
This function is intended for us as an onsubmit transformation.
|
| <static> |
validanguage.smartCommaSplit(Comma-delimited)
This function splits a string into an array using commas as the delimiter,
while being smart enough to ignore commas appearing inside parenthesis and
braces.
|
| <static> |
validanguage.sniffBrowser()
Determines roughly which browser they're using.
|
| <static> |
validanguage.toggle(toggleArgs)
Transformation supporting 3 major features: toggling visibility,
changing the values of form fields and adding options to select
elements.
|
| <static> |
validanguage.toggleCriteriaMet(field, criteria, settings)
Determines whether the criteria used by the toggle function
has been met
|
| <static> |
validanguage.toggleDisplay(nodeId, visibility)
Function used to hide or show a node.
|
| <static> |
validanguage.validateCharacters(text)
Validates that a field does not contain any of the invalid characters
listed in the characters validation rules.
|
| <static> |
validanguage.validateCreditCard(text, cardTypes, testChecksum)
Validates that a valid credit card number has been supplied
|
| <static> |
validanguage.validateDate(text, Options)
Validates that a valid date is supplied and is entered in the correct format.
|
| <static> |
validanguage.validateDateExists(year,, month, day)
Helper function to verify a date actually exists.
|
| <static> |
validanguage.validateEmail(text)
Validates an email address
|
| <static> |
validanguage.validateForm(Id)
Calls the validationWrapper function on the passed form ID
|
| <static> |
validanguage.validateIP(text)
Validates that a field contains a valid IPv4 address
|
| <static> |
validanguage.validateKeypress(e)
Function to suppress the keys specified in validanguage.el.characters
from being entered into a textarea or text box.
|
| <static> |
validanguage.validateMaxlength(text, max)
Validates that a field is less than maxlength characters long
|
| <static> |
validanguage.validateMinlength(text, min)
Validates that a field is greater than minlength characters long
|
| <static> |
validanguage.validateNumeric(text)
Validates that a field is numeric
|
| <static> |
validanguage.validateRegex(text, optional)
Validates the element against a user-defined regex stored in
validanguage.el[id].regex
|
| <static> |
validanguage.validateRequired(text)
Validates whether or not an element has been filled out,
selected or checked.
|
| <static> |
validanguage.validateRequiredAlternatives(e)
This function calls the validateRequired method on the "master/required"
form field when the "alternative" form field is clicked and then calls
the appropriate onerorr/onsuccess function.
|
| <static> |
validanguage.validateRequiredChild(text)
Child function called by validateRequired to validates whether or not an element has been filled out,
selected or checked.
|
| <static> |
validanguage.validateTimestamp(text, Options)
Validates that the entered text is a valid timestamp.
|
| <static> |
validanguage.validateURL(text)
Validates a URL
|
| <static> |
validanguage.validateUSDate(text)
DEPRECATED - Please use validateDate() instead as validateUSDate
will be removed in the future.
|
| <static> |
validanguage.validateUSPhoneNumber(text)
Validates that a US Phone number is entered
|
| <static> |
validanguage.validateUSSSN(text)
Validates that a US Social Security Number is entered
|
| <static> |
validanguage.validateUSZipCode(text)
Validates that a US zip code was entered
|
| <static> |
validanguage.validationWrapper(e, Custom)
This is a wrapper for all the validation event handlers assigned to both
form field element and to forms themselves.
|
| <static> |
validanguage.whichFormAmI(Form)
This function returns the ID of a form, if it exists.
|
Namespace Detail
validanguage
The validanguage library was written by DrLongGhost in 2008. See attached MIT_License.js
and readme.txt for licensing and documentation. Visit http://www.drlongghost.com/ for updates.
Author: DrLongGhost.
Author: DrLongGhost.
Field Detail
<static>
validanguage.useLibrary
Valid values are 'none', 'prototype', and 'scriptaculous'.
- Default Value:
- 'none'
Method Detail
<static>
validanguage.addEvent(Object, Event, Function)
Generic cross-browser addEvent() function.
- Parameters:
- {Object} Object
- to receive the event
- {Object} Event
- type
- {Object} Function
- to be called
<static>
validanguage.addEventInit()
Reassigns the validanguage.addEvent function, if an external library is being used.
<static>
validanguage.addOrCreateValidationWrapper(Form, eventType,, validationsCounter,)
This function wraps multiple validanguage.el.elemId.validations event handlers
and transformations within a single wrapper to call all loaded validations/transformations
and exit as soon as a validation returns false.
- Parameters:
- {Object} Form
- element object
- {string} eventType,
- such as "blur" or "keydown"
- {integer} validationsCounter,
- denotes the array index of this item in validanguage.el.elemId.validations
<static>
validanguage.addValidation(elemId, eventTypes, validationNames)
This function is used to either load a new validation for a form field, or to
reactivate a validation previously removed with the removeValidation() method.
NOTE: When adding a new validation, you will need to have previously inserted
all the relevant details about the validation in the validanguage.el.formField
object.
- Parameters:
- {String} elemId
- {String/Array} eventTypes
- {String/Array/Function} validationNames
<static>
validanguage.ajax(url, callback)
Very simple AJAX function
- Parameters:
- {String} url
- {Function} callback
<static>
validanguage.ajaxInit()
Initializes validanguage.ajax as browser-specific
<static>
validanguage.concatCollection(obj1, obj2)
Combines 2 node lists into 1
- Parameters:
- {Object} obj1
- {Object} obj2
<static>
validanguage.empty(testVar, falseIsEmpty)
Emulates PHP's empty() function. For convenience, you can specify whether
boolean false is considered empty. Defaults to false is NOT empty.
Ignores functions.
- Parameters:
- {Object} testVar
- {bool} falseIsEmpty
<static>
validanguage.format(Pattern, String, Regular)
This is a preset transformation which is used to reformat text input
to match a desired pattern
- Parameters:
- {String} Pattern
- using x to represent alphanumeric characters. For example: "(xxx) xxx-xxxx"
- {String} String
- listing any characters to be removed from the form field's value prior to potential reformatting For example: "()- "
- {String/Regex} Regular
- expression which, if provided, will be used to determine whether or not to proceed with reformatting. If not provided, the function will only reformat if the number of characters in the form field (after stripThese is applied) matches the number of x's in the provided pattern
<static>
validanguage.getCharCode(suppliedCharacter)
This function is one big ass switch case to look up a char code
for the supplied character
- Parameters:
- {String} suppliedCharacter
<static>
validanguage.getComments(el)
Fetches all comment nodes in the passed form node and returns them in a node list
Doesnt work in konqueror, since konqueror strips all comments from the DOM
- Parameters:
- {Containing Node} el
<static>
validanguage.getDateTimeDefaultOptions(options, defaults)
Helper function used by validateDate() and validateTimestamp().
- Parameters:
- {Object} options
- object provided by the user to validateDate() or validateTimestamp().
- {Object} defaults
- which should be used. Used to allow validateDate() and validateTimestamp() to have different default dateOrder values.
<static>
validanguage.getElSetting(Name, ID)
This function checks for a given setting in increasing specificity
within the validanguage.forms[formId].settings object, and within the passed
validanguage.el objects
- Parameters:
- {string} Name
- of the setting to be retrieved
- {string} ID
- of the form field object being validated
- {Object} validanguage.el.objId.validations[index]
- object
<static>
{Object}
validanguage.getFormSettings(id)
This function returns the validanguage.form[formId].setting object for the passed element ID
- Parameters:
- {string or Node} id
- of the input field or input node
- Returns:
- {Object} settings object
<static>
{String}
validanguage.getSettingFromComment(Name, Full)
This function parses the passed comment to retrieve the indicated setting
- Parameters:
- {String} Name
- of the setting to retrieve / needle
- {String} Full
- text of the HTML comment / haystack
- Returns:
- {String} The value of the requested setting
<static>
validanguage.hideError()
This function hides the div containing the validanguage error messages for
failed validations
<static>
validanguage.inArray(needle, haystack)
Determines whether the passed item is present in the array or object.
- Parameters:
- {Object} needle
- {Object} haystack
<static>
validanguage.inheritIfDefined(settingsHaystack, settingsNeedles, settingsTarget, constrainType)
This function searches settingsHaystack for all variables defined in the settingsNeedles
array, and if they are located, they are copied over to the settingsTarget
- Parameters:
- {Object} settingsHaystack
- -- Object location to be searched for settings
- {Array} settingsNeedles
- -- Array of settings to be checked
- {Object} settingsTarget
- -- Object location where any defined settings should be copied to
- {String} constrainType
- -- Optional type constraint
<static>
validanguage.init()
Initialization function for validanguage. Adds the onload hook
which fires off the populate() method to add all the other event
handlers
<static>
validanguage.insertAfter(nodeToAdd, referenceNode)
Function to insert 1 Node after another in the DOM. If the referenceNode
is a label, this function will use the nextSibling instead
- Parameters:
- {Node} nodeToAdd
- {Node} referenceNode
<static>
validanguage.loadCommentAPI(For)
This function parses all comments in the current document, looking for
the comment-based API and converts any validanguage statements it
finds into the element/json-based API for further processing.
- Parameters:
- {Array} For
- konqueror, we pass this function an Array with all the comments (retrieved via AJAX) For all other browsers, konquerorComments is undefined and we retrieve the comments normally via the DOM
<static>
validanguage.loadElAPI()
This function parses the validanguage.el object to load all the
form-element-specific validation settings which the end user has defined
via the Object-based API
<static>
{Array}
validanguage.parseSubstring(startChar, endChar, subject)
This function searches the passed subject and returns an Array of strings
which are delimited by the characters passed to the function in the
first 2 arguments. Used to pull comments from the document source
- Parameters:
- {String} startChar
- {String} endChar
- {String} subject
- Returns:
- {Array}
<static>
validanguage.populate()
Main function to be called onload to load all the validations
<static>
validanguage.removeValidation(elemId, eventTypes, validationNames)
This function is used to deactivate a previously loaded validation.
Provide the element ID of the field and a list of event types and validation
names to deactivate. You can use the * character as the eventType and/or
the validationName arguments to include ALL eventTypes/validationNames.
NOTE: if you are tempted to use removeValidation('id','*','*'), you may be
better off using validanguage.el.id.disabled=true, as this is much easier to
undo later.
NOTE: It is up to you to make sure no error msgs are displaying before disabling
a validation. If one is showing and all validations are disabled, the onsuccess
handlers used to clear the error msgs will never be called.
- Parameters:
- {String} elemId
- {String/Array} eventTypes
- {String/Array/Function} validationNames
<static>
{Array of Functions}
validanguage.resolveArray(args, returnType, ignoreCommas)
This function accepts as input a function, a string, an array of
functions, an array of strings, or a comma-delimited list of functon
names as its argument and returns an Array of functions or strings
comprising the passed arguments. Example: transforms 'foo, bar'
to [foo, bar]
- Parameters:
- {Function or String or Array} args
- {String} returnType
- should be either 'string' or 'function'
- ignoreCommas
- Returns:
- {Array of Functions}
<static>
validanguage.safeAlert(errorMsg)
This function shows an alert box and uses a counter to help prevent
infinite loops which can be created by the interaction between an alert()
statement and an onblur handler on an element.
- Parameters:
- {string} errorMsg
<static>
validanguage.showError(Text)
This function shows the error messages for failed validations by dynamically
creating a div
- Parameters:
- {string} Text
- of the error message to be displayed
<static>
validanguage.showSubmitMessage(validationResult, failedValidations)
This function is intended for us as an onsubmit transformation. It replaces the form's
submit button with the text specified in settings.showSubmitMessageMessage.
- Parameters:
- {Object} validationResult
- {Object} failedValidations
<static>
{Array}
validanguage.smartCommaSplit(Comma-delimited)
This function splits a string into an array using commas as the delimiter,
while being smart enough to ignore commas appearing inside parenthesis and
braces.
- Parameters:
- {string} Comma-delimited
- string
- Returns:
- {Array}
<static>
validanguage.sniffBrowser()
Determines roughly which browser they're using. Defaults to FF for anything
that isnt IE, Opera, Konqueror or Safari, which assuming the browser is standards-compliant,
should be good enough for what I'm using it for. Yea, yea, I know....
<static>
validanguage.toggle(toggleArgs)
Transformation supporting 3 major features: toggling visibility,
changing the values of form fields and adding options to select
elements.
- Parameters:
- {Array} toggleArgs
- Array of objects
<static>
validanguage.toggleCriteriaMet(field, criteria, settings)
Determines whether the criteria used by the toggle function
has been met
- Parameters:
- {Object} field
- {string} criteria
- {Object} settings
- object
<static>
validanguage.toggleDisplay(nodeId, visibility)
Function used to hide or show a node. This function will also automatically disable or enable
any form fields contained within the passed node.
- Parameters:
- {Object} nodeId
- ID of the node to hide/show
- {Object} visibility
- (optional) Pass either 'none' or '' to hide/show. Or leave blank to toggle
<static>
validanguage.validateCharacters(text)
Validates that a field does not contain any of the invalid characters
listed in the characters validation rules.
- Parameters:
- {string} text
<static>
validanguage.validateCreditCard(text, cardTypes, testChecksum)
Validates that a valid credit card number has been supplied
- Parameters:
- {string} text
- {array} cardTypes
- {boolean} testChecksum
- Pass false to skip the luhn checksum test
<static>
validanguage.validateDate(text, Options)
Validates that a valid date is supplied and is entered in the correct format.
The format is specified by the following arguments
- Parameters:
- {String} text
- to be validated
- {Object} Options
- object containing any of the following options
dateOrder: {String} This must be either 'ymd','mdy','dmy','myd','ydm', or 'dym
allowedDelimiters: {String}. A string containing the list of delimiters which are allowed. Example: './-'
twoDigitYearsAllowed: {Boolean}. Is a 2-digit year valid
oneDigitDaysAndMonthsAllowed: {Boolean}. Is a 1-digit month or a 1-digit day valid
maxYear: {Integer}. Years greater than maxYear will be treated as invalid. Defaults to 15 years from today
minYear: {Integer}. Years less than minYear will be treated as invalid. Defaults to 1900
rejectDatesInTheFuture: {Boolean}. Are dates in the future valid? rejectDatesInTheFuture defaults to false
rejectDatesInThePast: {Boolean}. Are dates in the past valid? rejectDatesInThePast defaults to false
<static>
{Boolean}
validanguage.validateDateExists(year,, month, day)
Helper function to verify a date actually exists. Used to reject values
such as "12/35/2009"
- Parameters:
- {integer} year,
- preferably 4-digit
- {integer} month
- {integer} day
- Returns:
- {Boolean}
<static>
validanguage.validateEmail(text)
Validates an email address
- Parameters:
- text
<static>
{Object}
validanguage.validateForm(Id)
Calls the validationWrapper function on the passed form ID
- Parameters:
- {String or Form Node} Id
- of the form
- Returns:
- {Object} Object containing 2 elements: Object.result is a boolean to indicate whether any fields in the form failed validation Object.failedValidations will contain info detailing any form fields with failed validations
<static>
validanguage.validateIP(text)
Validates that a field contains a valid IPv4 address
- Parameters:
- text
<static>
validanguage.validateKeypress(e)
Function to suppress the keys specified in validanguage.el.characters
from being entered into a textarea or text box.
This function must be forked to fetch the keyCode
and differentiate between control and non-control characters.
For example: in Mozilla both the delete key and . equate to 46.
We dont fork based on supported functions because IE and Moz event models
for keyCodes/charCodes are different and confusing, so we're
better off sniffing the browser.
- Parameters:
- {Event Object} e
<static>
validanguage.validateMaxlength(text, max)
Validates that a field is less than maxlength characters long
- Parameters:
- {string} text
- max
<static>
validanguage.validateMinlength(text, min)
Validates that a field is greater than minlength characters long
- Parameters:
- {string} text
- min
<static>
validanguage.validateNumeric(text)
Validates that a field is numeric
- Parameters:
- {string} text
<static>
validanguage.validateRegex(text, optional)
Validates the element against a user-defined regex stored in
validanguage.el[id].regex
- Parameters:
- {string} text
- {object} optional
- object containing regex settings
<static>
validanguage.validateRequired(text)
Validates whether or not an element has been filled out,
selected or checked. This function is a wrapper which
calls validateRequiredChild()
- Parameters:
- {string} text
<static>
validanguage.validateRequiredAlternatives(e)
This function calls the validateRequired method on the "master/required"
form field when the "alternative" form field is clicked and then calls
the appropriate onerorr/onsuccess function.
- Parameters:
- e
<static>
validanguage.validateRequiredChild(text)
Child function called by validateRequired to validates whether or not an element has been filled out,
selected or checked. validateRequiredChild is required to add support for the requiredAlternatives
array.
- Parameters:
- {string} text
<static>
validanguage.validateTimestamp(text, Options)
Validates that the entered text is a valid timestamp. The options object supports all the options listed
under the validateDate function as well as the following additional onces
- Parameters:
- {String} text
- to be validated
- {Object} Options
- object containing any of the following options:
timeIsRequired: {Boolean} Is a date which is provided without an accompanying time considered a valid timestamp? timeIsRequired defaults to false.
timeUnits: {String} A string containing a list of all the time units which are allowed to be entered in the timestamp. These may include any of the following: h for hours, m for minutes, s for seconds, u for microseconds, and t for timezone. Example: "hms" for hours, minutes and seconds or "hmsut" for all 5 units. Defaults to "hms"
microsecondPrecision {Integer} Indicates the supported number of decimal places for the microseconds. Defaults to 6.
<static>
validanguage.validateURL(text)
Validates a URL
- Parameters:
- {string} text
<static>
validanguage.validateUSDate(text)
DEPRECATED - Please use validateDate() instead as validateUSDate
will be removed in the future. validateDate() defaults to MM/DD/YYYY
when called without any additional arguments.
- Parameters:
- {string} text
<static>
validanguage.validateUSPhoneNumber(text)
Validates that a US Phone number is entered
- Parameters:
- {string} text
<static>
validanguage.validateUSSSN(text)
Validates that a US Social Security Number is entered
- Parameters:
- {string} text
<static>
validanguage.validateUSZipCode(text)
Validates that a US zip code was entered
- Parameters:
- {string} text
<static>
validanguage.validationWrapper(e, Custom)
This is a wrapper for all the validation event handlers assigned to both
form field element and to forms themselves. This function also calls any
transformations before running the validations.
We use a wrapper for a number of reasons, including exiting validation
early as soon as a single validation function fails.
- Parameters:
- {Event Object} e
- {String} Custom
- Event '
<static>
{String}
validanguage.whichFormAmI(Form)
This function returns the ID of a form, if it exists. Otherwise, it
returns the form's index position in the document.forms array.
By using this function, we need not require all forms to have
distinct IDs.
- Parameters:
- {DOM Node} Form
- Node
- Returns:
- {String} Form ID or Index position