JS Toolbox

Download Toolbox.zip (8K)

NOTE: I recently revamped parts of Toolbox.js to make it more CF-like. This included removing some unused functions including the PIN functions and isNum() and changing isDate(), isDateString(), isTime() and isTimeString(). isDate() and isTime() are now isYMD() and isHMS() respectively, and isDateString() and isTimeString() have been renamed isDate() and isTime(). parseDate() and parseTime() have been replaced with dateParse(). isDateTime() and parseDateTime() functions have been replaced by isDate(). Confusing, I know, but I don't know if anybody uses this library but me anyway!

Requires JavaScript 1.2-compliant browser.

Toolbox.js is a JavaScript library based on the Sample Code for Form Validation from Netscape. This library has been modified to use JavaScript 1.2 (mainly for access to regular expressions) and should work on any compliant browser including Firefox, NS 6+ and IE 5+. I've used it for quite awhile and it appears stable, but I do not guarantee it to be bug free! Let me know if you have comments or suggestions.

I am very particular about download speed so I made the library file as small as possible (about 25K). To accomplish this, variable names are purposely very short, inline code documentation has been omitted and all unnecessary whitespace has been removed.

Since I developed it for my own use rather than to formally distribute the source code, the user documentation is very basic--just info on parameters with no in-depth info on use. The following are brief instructions. If you need help with JS basics or using JS libraries, please check out DMOZ's list of JS resources.

  1. Put Toolbox.js in the root directory of the web server

  2. Include the library file on each page where you want to use the functions by putting the following code in the document head:
    <SCRIPT LANGUAGE="JavaScript" SRC="/Toolbox.js"></SCRIPT>

  3. Call Toolbox.js functions like this:
    <SCRIPT LANGUAGE="JavaScript">
    function myFunction(s) {
    	if (findNoCase('foo',s) == 0) {
    		alert('No Foo!');
    	} else {
    		document.MyForm.MyField.value = trim(s);
    	}
    }
    function showDate() {
    	alert('Today is ' + dateFormat(now(),'mm/dd/yy'));
    }
    </SCRIPT>

  4. For form validation:

    1. Create a validation function in this style:
      <SCRIPT LANGUAGE="JavaScript">
      function doValidation(oForm) {
      	if (!validateNumber(oForm.Field1,'Entry is invalid')) return false;
      	if (!validateDate(oForm.Field2,'Date is invalid')) return false;
      	// More validation here, as needed
      	return true;
      }
      </SCRIPT>

      A common mistake is to add the ".value" property on to the field object name. Don't!

    2. Call the validation function using the form's onSubmit event handler
      <FORM ... onSubmit="return doValidation(this);">
Don't forget that JS is case-sensitive. All function names must be in the correct case. The convention followed is initial letter lower and all other words first letter capital, like this: myFunctionName(). Acronyms keep all caps, like this: isSSN(). Note that all of the functions in the library are available to any JavaScript on the page. Below is more detailed documentation.


Top · Validation Functions · Transform/Create Functions · Evaluation Functions · Action Functions

Validation Functions

validateBarcode(oField[,sMessage,bReset,bEmptyOK,bSelect])

Returns true if form field contains a barcode number. Validates UPCA and EAN13. Validates format only, not actual existence of barcode.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateBarcode(document.Form.Field);
validateBarcode(document.Form.Field,'Invalid Barcode number','','',true);

validateCreditCard(oField[,sMessage,bReset,bEmptyOK,bSelect])

Returns true if form field contains a credit card number. Validates MasterCard, Visa, AmericanExpress, DinersClub, Discover, EnRoute and JCB. Validates format only, not actual existence of credit card.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateCreditCard(document.Form.Field);
validateCreditCard(document.Form.Field,'Invalid Credit Card number','','',true);

validateDate(oField[,sMessage,dMin,dMax,bReset,bEmptyOK,bSelected,sFormat])

Returns true if a form field contains a valid date of 1/1/1000 A.D. or later. Accepts most common date formats (MM/DD/YY, M-D-YYYY, D MMM YY, MMM D YYYY, MM.DD.YY, ISDN, etc.) Accepts 2- or 4-digit years. 2-digit years from 00 to 29 are treated as 2000 to 2029. Valid dates can be formatted using standard CF-style date formats.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

dMin
Optional. Minimum date as object or string. Default is none.

dMax
Optional. Maximum date as object or string. Default is none.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

sFormat
Optional. String indicating format (see dateFormat() below) to apply to date if validation succeeds. Default is no formatting.

Examples
validateDate(document.Form.Field);
validateDate(document.Form.Field,'Date must be in March 1995','3/1/1995','31 Mar 1995',true,'','','mm/dd/yyyy');

validateEmail(oField[,sMessage,bReset,bEmptyOK,bSelect,bCommon])

Returns true if a form field contains a properly formatted email address according to RFC 3696. Validates format only, not actual existence of email address.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it

bCommon
Optional. Boolean indicating whether email address must be a "Common" format. Setting this to true means the local-part (the part to the left of the @ sign) can contain only alphanumerics, periods, hyphens and underscores. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateEmail(document.Form.Field);
validateEmail(document.Form.Field,'Invalid email address','',true,true);

validateEntry(oField[,sMessage,nMinLen,nMaxLen,bReset,bEmptyOK,bSelect])

Returns true if a form field contains data.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

nMinLen
Optional. Minimum length of entry as an integer greater than zero. Default is 1.

nMaxLen
Optional. Maximum length of entry as an integer greater than zero. Default is none.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateEntry(document.Form.Field);
validateEntry(document.Form.Field,'If entered, this field must be 10 or fewer characters','',10,'',true,true);

validateFEIN(oField[,sMessage,bReset,bEmptyOK,bSelect,bFormat])

Returns true if a form field contains a Federal Employer Identification Number. Validates format only, not actual existence of FEIN.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

bFormat
Optional. Boolean indicating whether to apply "xx-xxxxxxx" format to value if validation succeeds. Default is false.

Examples
validateFEIN(document.Form.Field);
validateFEIN(document.Form.Field,'An FEIN is required',true,'',true,true);

validateInteger(oField[,sMessage,nMin,nMax,bReset,bEmptyOK,bNoSign,bSelect])

Returns true if a form field contains an integer. Value can be positive or negative.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

nMin
Optional. Minimum value of entry. Default is none.

nMax
Optional. Maximum value of entry. Default is none.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bNoSign
Optional. Boolean indicating whether to reject signed (+ or -) values. Setting this to true means a signed value will fail validation. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateInteger(document.Form.Field);
validateInteger(document.Form.Field,'Field must be between 1 and 10',1,10,'',true,true,'');

validateIP(oField[,sMessage,bReset,bEmptyOK,bSelect])

Returns true if form field contains a properly formatted IP address. Validates format only, not actual existence of IP address.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateIP(document.Form.Field);
validateIP(document.Form.Field,'Invalid IP address','',true,true);

validateLength(oField,nLen[,sMessage])

Returns true if a form field value does not exceed a specified length. Intended to limit entries in text areas using the "onKeyUp" event handler.

oField
Required. Form field object to validate.

nLen
Required. Maximum length for field value.

sMessage
Optional. Message to display if length is exceeded. Default is 'Field has exceeded the nLen character limit'. Single asterisk (*) suppresses message.

Examples
onKeyUp = "validateLength(this,50);"

validateNumber(oField[,sMessage,nMin,nMax,bReset,bEmptyOK,bNoSign,bSelect])

Returns true if a form field contains an integer or decimal/floating point number. Value can be positive or negative.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

nMin
Optional. Minimum value of entry. Default is none.

nMax
Optional. Maximum value of entry. Default is none.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bNoSign
Optional. Boolean indicating whether to reject signed (+ or -) values. Setting this to true means a signed value will fail validation. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateNumber(document.Form.Field);
validateNumber(document.Form.Field,'Field must be 7.5 or more',7.5,'','','',true);

validateNumberGT(oField,sMessage,nNumber[,bReset,bEmptyOK,bNoSign,bSelect])

Returns true if a form field contains an integer or decimal/floating point number greater than an arbitrary number. Typically used in place of the validateNumber function to handle "greater than zero" situations. The validateNumber function requires a minimum number, but what is the minimum number that is greater than zero? .001? .0000000001? You must use a "greater than" to handle this situation.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

nNumber
Required. Number used for "greater than" comparison.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bNoSign
Optional. Boolean indicating whether to reject signed (+ or -) values. Setting this to true means a signed value will fail validation. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

Examples
validateNumberGT(document.Form.Field,'Entry must be greater than zero',0);
validateNumberGT(document.Form.Field,'If entered, this field must be greater than 500',500,'',true,'',true);

validatePhone(oField[,sMessage,bReset,bEmptyOK,bSelect,bFormat])

Returns true if form field contains a U.S. area code, telephone number and optional U.S. country code prefix. Accepts area codes with or without parentheses and any combination of spaces, dashes, slashes or dots as separators. Also accepts "xxxxxxxxxx". Validates official NANPA format only, not actual existence of telephone number.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected (highlighted). Default is false.

bFormat
Optional. Boolean indicating whether to apply "(xxx) xxx-xxxx" format to value if validation succeeds. Default is false.

Examples
validatePhone(document.FormName.Fieldname);
validatePhone(document.FormName.Fieldname,'Invalid phone number','','','',true);

validateSSN(oField[,sMessage,bReset,bEmptyOK,bSelect,bFormat])

Returns true if a form field contains a Social Security Number. Validates format only, not actual existence of SSN.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

bFormat
Optional. Boolean indicating whether to apply "xxx-xx-xxxx" format to value if validation succeeds. Default is false.

Examples
validateSSN(document.Form.Field);
validateSSN(document.Form.Field,'An SSN is required',true,'',true,true);

validateTime(oField[,sMessage,dMin,dMax,bReset,bEmptyOK,bSelect,sFormat])

Returns true if a form field contains a valid time. Accepts 24-hour and AM/PM formats, with minutes and seconds optional (HH:MM:SS, HH:MM, HH, HH:MM:SS AM/PM, HH:MM AM/PM, HH AM/PM).

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

dMin
Optional. Minimum time as date object or string. Default is none.

dMax
Optional. Maximum time as date object or string. Default is none.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

sFormat
Optional. String indicating format (see timeFormat() below) to apply to time if validation succeeds. Default is no formatting.

Examples
validateTime(document.Form.Field);
validateTime(document.Form.Field,'If entered, time must be during work hours','9am','5pm',true,true,true);

validateZIPCode(oField[,sMessage,bReset,bEmptyOK,bSelect,bFormat])

Returns true if a form field contains a properly formatted 5- or 9-digit ZIP code. Validates format only, not actual existence of ZIP code.

oField
Required. Form field object to validate.

sMessage
Optional. Message to display if validation fails. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value if validation fails. Default is false.

bEmptyOK
Optional. Boolean indicating whether field can be empty. Setting this to true means an entry is not required in the field but if anything is entered it will be validated. Default is false.

bSelect
Optional. Boolean indicating whether field value should be selected if validation fails. Default is false.

bFormat
Optional. Boolean indicating whether a 9-digit value should be formatted to "xxxxx-xxxx". Default is false.

Examples
validateZIPCode(document.Form.Field);
validateZIPCode(document.Form.Field,'A ZIP Code is required','','',true);

doFARS(oField[,sMessage,bReset,bSelect])

Sets focus to field and optionally shows alert, selects field or resets to default value. FARS means "Focus, Alert, Reset, Select".

oField
Required. Form field object.

sMessage
Optional. Message to display. Default is 'Entry is invalid'. Single asterisk (*) suppresses message.

bReset
Optional. Boolean indicating whether field should be reset to default value. Default is false.

bSelect
Optional. Boolean indicating whether field should be selected (highlighted). Default is false.

Examples
doFARS(document.Form.Field);
doFARS(document.Form.Field,'This field is required','',true);


Top · Validation Functions · Transform/Create Functions · Evaluation Functions · Action Functions

Transform/Create Functions

These functions return object, number or string values. Note that all indexes follow the CF standard and begin with 1 rather than 0.

_escape(string)

Returns: string
Returns string with certain characters replaced by hexadecimal escape sequences. Uses encodeURIComponent() if available, otherwise uses escape().

_unescape(string)

Returns: string
Returns string with any hexadecimal escape sequences replaced by the characters they represent. Uses decodeURIComponent() if available, otherwise uses unescape().

abs(number)

Returns: number
Returns number as unsigned value.

autoTrunc(string[,length])

Returns: string
Returns string truncated to length characters. Elipsis (...) is appended. Default length is 30.

chop(string[,count])

Returns: string
Returns string with last count characters removed. Default is 1 character.

chr(number)

Returns: string
Returns ASCII character number. Valid values are 0 to 127. Extended ASCII characters are not supported (returns empty string).

createDate(year[,month,day])

Returns: date object
If omitted, month and day default to '1'. Time is set to 00:00:00. If year, month or day is invalid, returns empty string.

createDateTime(year[,month,day,hour,minute,second])

Returns: date object
If omitted, month and day default to '1'. If hour, minute or second are omitted, they default to '0'. If year, month, day, hour, minute or second is invalid, returns empty string.

createTime(hour[,minute,second])

Returns: date object
If minute or second are omitted, they default to '0'. Today's date will be used. If hour, minute or second is invalid, returns empty string.

cTrim(string[,number1,number2])

Returns: string
Character trim. Returns string with number1 characters removed from the beginning of string and number2 characters removed from the end of string. If omitted, number2 is set to equal number1. Default for number1 is 1 character.

dateAdd(datepart,number[,date])

Returns: date object
Adds number to the datepart of date. date can be object or string. If date is omitted, current date is used. If datepart is invalid, date is not changed.

Datepart     Description
s seconds
n minutes
h hours
d,y days
ww 7-day weeks
m months
q quarters
yyyy years

dateCompare(date1[,date2,datepart])

Returns: number
Compares date1 to date2. Returns -1 if date1 is before date2, 0 if they are the same and 1 if date1 is after date2. Dates can be objects or strings. If date2 is omitted, current date/time is used. datepart sets the precision of the comparison. Default is to the second.

Datepart     Description
s seconds
n minutes
h hours
d days
m months
yyyy years

dateDiff(datepart,date1,date2)

Returns: number
Returns number of whole dateparts by which date1 is less than date2. Does not account for Daylight Saving Time adjustments when datepart is hours, minutes or seconds.

Datepart     Description
s seconds
n minutes
h hours
d days
m months
yyyy years

dateFormat([date,mask])

Returns: string
Formats date according to mask. date can be object or string. If date is omitted, current date is used. Default mask is 'dd-mmm-yy'. Returns empty string if date is invalid.

Mask     Description
d Day of month as number, no leading zero
dd Day of month as number, with leading zero
ddd Three-letter abbreviation for day of week
dddd Full name of day of week
m Month as number, no leading zero
mm Month as number, with leading zero
mmm Three-letter abbreviation for month
mmmm Full name of month
y Two-digit year, no leading zero
yy Two-digit year, with leading zero
yyyy Four-digit year

dateParse(string)

Returns: date object or empty string
If string is a valid date string, converts it to a date object, otherwise returns an empty string. Time is set to 00:00:00. If string is timestamp (yyyy-mm-dd hh:mm:ss), time is used. If string is time only, time is used and date is set to 30 Dec 1899.

datePrecision(datepart[,date])

Returns: date object
Adjusts date by setting all date values up through datepart to their minimum values. Useful when comparing dates. date can be object or string. If date is omitted, current date is used.

Datepart     Description
s seconds
n minutes
h hours
d days
m months
yyyy years

day([date])

Returns: number
Day of month of date as a number between 1 and 31. date can be object or string. If date is omitted, returns current day.

dayOfWeek([date])

Returns: number
Day of week for date as a number between 1 (Sunday) and 7 (Saturday). date can be object or string. If date is omitted, uses current day of week.

dayOfWeekAsString([value])

Returns: string
Name of the day of week for value. value can be a number between 1 (Sunday) and 7 (Saturday), a date string or a date object. If value is omitted, uses current day of week.

daysInFeb([year])

Returns: number
Number of days in February of year. Calculates leap-years. If year is omitted, uses current year.

daysInMonth([date])

Returns: number
Number of days in the month of date. date can be object or string. If date is omitted, uses current month.

decimalFormat(number[,bNoCommas])

Returns: string
Formats number with comma-separated thousands and two decimal places. Returns number unchanged if it cannot be converted to a valid decimal. If bNoCommas is true, commas are omitted. Default bNoCommas is false.

dollarFormat(number[,bNoCommas])

Returns: string
Formats number with a leading dollar sign, comma-separated thousands, and two decimal places. Returns number unchanged if it cannot be converted to a valid dollar value. If bNoCommas is true, commas are omitted. Default bNoCommas is false.

find(substring,string[,startpos])

Returns: number
Location of substring within string, search beginning at startpos (default is '1'). Case-sensitive.

findNoCase(substring,string[,startpos])

Returns: number
Location of substring within string, search beginning at startpos (default is '1'). Case-insensitive.

fix(number)

Returns: number
Converts number to an integer. If number is greater than zero, returns closest integer less than number. If number is less than zero, returns closest integer greater than number.

formatFEIN(string)

Returns: string
Formats string as a Federal Employer Identification Number (xx-xxxxxxx). Returns string unchanged if it cannot be converted to a valid FEIN.

formatSSN(string)

Returns: string
Formats string as a Social Security Number (xxx-xx-xxxx). Returns string unchanged if it cannot be converted to a valid SSN.

formatUSPhone(string)

Returns: string
Formats string as a U.S. telephone number "(xxx) xxx-xxxx". Returns string unchanged if it cannot be converted to a valid phone number.

formatZIP(string)

Returns: string
Formats string as ZIP+4 (xxxxx-xxxx). Returns string unchanged if it cannot be converted to a valid ZIP+4.

getCookie(string)

Returns: string
Value of cookie named string. Returns empty string if cookie does not exist.

getObj(string)

Returns: object
Returns object reference for document element with ID string.

getOption(selectListObject,text[,target])

Returns: number
Returns JS index of the first option in selectListObject that matches text as the value. If target is "L" the match will be against the option label text. Match is case-sensitive. Returns -1 if text not found.

getValue(formfield[,delimiter])

Returns: string
Value of formfield. Returns multiple values (multiple selects, duplicate name checkboxes, etc.) as list delimited with delimiter. formfield must be a form field object.

gridFormat(string[,type,param1,param2,emptyString])

Returns: string
Value of string formatted with HTML entities for display in an HTML table or data grid. Null/empty values are converted to emptyString. Default emptyString is a non-breaking space (&nbsp;).

Type     Description
boolean boolean string formatted as "Yes" or "No"
date date string formatted using param1. Default is 'm/d/yyyy'.
decimal number rounded to two decimal places and formatted with commas. param1 is boolean to suppress commas.
integer number with decimals truncated (no rounding) and no commas
money number formatted as decimal (see above) with leading dollar sign. param1 is boolean to suppress commas.
number number rounded to integer and formatted with commas. param1 is boolean to suppress commas.
text text truncated to param1 characters with elipsis (...) Default is 30 characters.
time time string formatted using param1. Default is 'h:mm tt'.
timestamp timestamp string formatted using param1 for date and param2 for time. Defaults are 'm/d/yyyy' and 'h:mm tt'.

hour([date])

Returns: number
Hour portion of date as a number between 0 and 23. date can be date object, date string or time string. If date is omitted, returns current hour.

htmlEditFormat(string)

Returns: string
string formatted with HTML entities

Character     HTML Entity
& &amp;
" &quot;
> &gt;
< &lt;

initCap(string)

Returns: string
Converts first character of string to uppercase and the rest to lowercase.

lastMonthEnd()

Returns: date object
Date of the last day of last month with time of 00:00:00.

lastMonthStart()

Returns: date object
Date of the first day of last month with time of 00:00:00.

lCase(string)

Returns: string
Converts string to lowercase.

left(string[,number])

Returns: string
Left-most number characters of string. Default is 1 character.

len(string)

Returns: number
Length of string. Returns 0 if string is empty or null.

listAppend(list,string[,delimiter])

Returns: string
Appends delimiter and string to the end of list. Default delimiter is a comma. If delimiter is an empty string, list is returned unchanged.

listChop(list[,delimiter])

Returns: string
Returns list with last element removed. Default delimiter is a comma.

listContains(list,substring[,delimiter])

Returns: number
Index position of the first element of list that contains substring. Returns 0 if not found or if substring is null or empty. Default delimiter is a comma. Search is case-sensitive.

listContainsNoCase(list,substring[,delimiter])

Returns: number
Index position of the first element of list that contains substring. Returns 0 if not found or if substring is null or empty. Default delimiter is a comma. Search is not case-sensitive.

listDeleteAt(list,position[,delimiter])

Returns: string
Removes element of list at index position. Default delimiter is a comma.

listFind(list,string[,delimiter])

Returns: number
Index position of the first element of list that matches string. Returns 0 if not found or if string is null or empty. Default delimiter is a comma. Search is case-sensitive.

listFindNoCase(list,string[,delimiter])

Returns: number
Index position of the first element of list that matches string. Returns 0 if not found or if string is null or empty. Default delimiter is a comma. Search is not case-sensitive.

listFirst(list[,delimiter])

Returns: string
First element of list. Default delimiter is a comma.

listGetAt(list,position[,delimiter])

Returns: string
Element at index position of list. Default delimiter is a comma.

listLast(list[,delimiter])

Returns: string
Last element of list. Default delimiter is a comma.

listLeft(list[,number,delimiter])

Returns: string
First number elements from list. Delimiters trailing last element are truncated but all others are retained. Default number is 1. Default delimiter is a comma.

listLen(list[,delimiter])

Returns: number
Number of elements in list. Like CF, does not include empty/null elements. If list is null or empty, returns 0. Default delimiter is a comma.

listMid(list[,position,number,delimiter])

Returns: string
Returns number elements from list starting with element position. Leading and trailing delimiters are truncated but all others are retained. Default position is 1. Default number is 1. Default delimiter is a comma.

listPrepend(list,string[,delimiter])

Returns: string
Adds string and delimiter to the start of list. Default delimiter is a comma. If delimiter is an empty string, list is returned unchanged.

listRest(list[,delimiter])

Returns: string
All the elements of list excluding the first element. Default delimiter is a comma.

listRight(list[,number,delimiter])

Returns: string
Last number elements from list. Delimiters leading first element are truncated but all others are retained. Default number is 1. Default delimiter is a comma.

listToArray(list[,delimiter])

Returns: array
Converts list into an array. Like CF, empty/null list elements are discarded. Default delimiter is a comma.

lTrim(string)

Returns: string
Removes leading whitespace from string.

max(number1,number2)

Returns: number
Returns larger of number1 and number2.

maxDate(date1,date2)

Returns: date
Returns larger (ie, latest) of date1 and date2.

mid(string,startpos[,number])

Returns: string
number characters from string beginning at startpos. Default is 1 character.

min(number1,number2)

Returns: number
Returns smaller of number1 and number2.

minDate(date1,date2)

Returns: date
Returns smaller (ie, earliest) of date1 and date2.

minute([date])

Returns: number
Minute portion of date as a number between 0 and 59. date can be date object, date string or time string. If date is omitted, returns current minute.

month([date])

Returns: number
Month of date as a number between 1 and 12. date can be object or string. If date is omitted, returns current month.

monthAsString([value])

Returns: string
Name of the month of value. value can be a number between 1 (January) and 12 (December), a date string or a date object. If value is omitted, current month is used.

monthEnd([date])

Returns: date object
Last day of month of date with time of 00:00:00. date can be object or string. If date is omitted, current month is used.

monthStart([date])

Returns: date object
First day of month of date with time of 00:00:00. date can be object or string. If date is omitted, current month is used.

ms([date])

Returns: number
Number of milliseconds between date and 00:00:00 (GMT) 1 Jan 1970. date can be object or string. If date is omitted, current date is used.

nextMonthEnd()

Returns: date object
Last day of next month with time of 00:00:00.

nextMonthStart()

Returns: date object
First day of next month with time of 00:00:00.

now()

Returns: date object
Current local date and time.

numberFormat(number[,bNoCommas])

Returns: string
Formats number with comma-separated thousands. Decimal numbers will be rounded. Returns number unchanged if it cannot be converted to a valid number value. If bNoCommas is true, commas are omitted. Default bNoCommas is false.

nvl(arg1,arg2)

Returns: arg1 or arg2
Returns arg2 if arg1 is null or zero-length. arg1 or arg2 can be any valid JS datatype or object. Similar to the Oracle nvl() function.

objectToQueryString(object)

Returns: string
object can be a form, form field or object. Returned string is query string format: ampersand-delimited name/escaped-value pairs. For forms, fields without names are ignored.

randRange(number1,number2)

Returns: integer
Random integer within range of number1 and number2 (inclusive). Randomizer is seeded using ms().

reFind(regEx,string[,startpos])

Returns: number
Location of regEx within string, search beginning at startpos (default is '1'). Case-sensitive. NOTE: Some JavaScript regular expressions require specific string formatting and escaping. Please refer to JS docs.

reFindNoCase(regEx,string[,startpos])

Returns: number
Location of regEx within string, search beginning at startpos (default is '1'). Case-insensitive. NOTE: Some JavaScript regular expressions require specific string formatting and escaping. Please refer to JS docs.

removeChars(string,start[,count])

Returns: string
Removes count number of characters from string starting with character number start. If count is omitted, all remaining characters are removed. If start or count are invalid, returns string unchanged.

replace(string,substring1,substring2[,scope])

Returns: string
Replaces first occurrence of substring1 with substring2 in string according to scope. If scope is 'All', all occurrences of substring1 will be replaced. If substring1 or substring2 are omitted, returns string unchanged. Search is case-sensitive.

replaceCharsInBag(string1,string2,string3)

Returns: string
Returns string1 with each character in string2 replaced with string3. Search is case-sensitive.

replaceList(string,list1,list2[,delimiter])

Returns: string
Returns string with all occurrence of elements in list1 replaced with corresponding elements in list2. If list2 has only 1 element, it will be used for all replace actions. If list1 or list2 are omitted or do not have the same number of elements, returns string unchanged. Default delimiter is a comma. Search is case-sensitive.

replaceNoCase(string,substring1,substring2[,scope])

Returns: string
Replaces first occurrence of substring1 with substring2 in string according to scope. If scope is 'All', all occurrences of substring1 will be replaced. If substring1 or substring2 are omitted, returns string unchanged. Search is case-insensitive.

reverse(string)

Returns: string
Returns string with characters in reverse order.

right(string[,number])

Returns: string
Right-most number characters of string. Default is 1 character.

round(number[,decimalplaces])

Returns: number
number rounded to decimalplaces. Default is rounded to integer. Returns empty string if number is invalid.

rTrim(string)

Returns: string
Removes trailing whitespace from string.

second([date])

Returns: number
Second portion of date as a number between 0 and 59. date can be date object, date string or time string. If date is omitted, returns current second.

stripWhitespace(string)

Returns: string
Removes all whitespace from string including spaces, tabs, carriage returns, newlines and vertical tabs.

timeFormat([time/date,mask])

Returns: string
Formats time/date according to mask. time/date can be object or string. If time/date is omitted, current time is used. Default mask is 'hh:mm tt'. Returns empty string if time/date is invalid.

Mask     Description
h Hours as 12-hour clock, no leading zero
hh Hours as 12-hour clock, with leading zero
H Hours as 24-hour clock, no leading zero
HH Hours as 24-hour clock, with leading zero
m Minutes, no leading zero
mm Minutes, with leading zero
s Seconds, no leading zero
ss Seconds, with leading zero
t Single-letter meridian: A or P
tt Two-letter meridian: AM or PM

toBool(value)

Returns: boolean
Converts value to a boolean value. JavaScript true/false, numbers, 'Yes', 'No', 'True' and 'False' are converted to boolean equivalents. For numbers, any that evaluate to zero are false and all others are true. Any other value is false. Text matches are case-insensitive.

toBytes(number[,unit,spacer])

Returns: string
Converts number to the equivalent number of bytes and adds the appropriate unit label separated by spacer. The number and label will match unit if specified. Otherwise, the appropriate unit is selected. The number will use commas to separate thousands and two decimal places where needed. Uses binary kilobytes (=1024) for conversions.

Unit     Description     Conversion
B Bytes number
K Kilobytes number / 1024
M Megabytes number / 10242
G Gigabytes number / 10243
T Terabytes number / 10244
P Petabytes number / 10245

today()

Returns: date object
Today's date with time of 00:00:00.

toDHMS(date1,date2)

Returns: string
Returns Days, Hours, Minutes and Seconds between date1 and date2 formatted as "Nd, Nh, Nm, Ns". If value resolves to a value smaller than Day, Hour or Minute, they are omitted. Seconds will always be displayed.

toInt(value)

Returns: integer
Converts value to an integer. Decimals are truncated without rounding. Invalid value returns empty string.

tomorrow()

Returns: date object
Tomorrow's date with time of 00:00:00.

toStr(value)

Returns: string
Converts value to a string data type.

toYYYY(number)

Returns: number
Converts 2-digit number to 4-digit year, uses current year to current year+20 as 21st century and others as 20th.

trim(string)

Returns: string
Removes leading and trailing whitespace from string.

uCase(string)

Returns: string
Converts string to upper-case.

urlEncodedFormat(string)

Returns: string
Converts string to a valid URL-encoded value.

weekdayOfMonth(weekday,count[,date])

Returns: date object
Date for the count occurrence of weekday in month of date. weekday must be at least two letters (Mo, Mon, Monday, etc.) If count is less than zero, first occurrence is returned. If count exceeds number of weekdays in month, last occurrence is returned. date can be object or string. If date is omitted, uses current month.

year([date])

Returns: number
Year of date as a 4-digit number. date can be object or string. If date is omitted, returns current year.

yesNoFormat(boolean)

Returns: string
Returns boolean formatted as 'Yes' or 'No'.

yesterday()

Returns: date object
Yesterday's date with time of 00:00:00.


Top · Validation Functions · Transform/Create Functions · Evaluation Functions · Action Functions

Evaluation Functions

These functions all return a boolean (true/false) value.

isAlpha(value)

True if value contains only letters. Case-insensitive.

isAlphaNum(value)

True if value contains only letters or numbers. Case-insensitive.

isAMEX(value)

True if value is a valid format for an American Express credit card.

isAnyCC(value)

True if value is a valid format for a Mastercard, VISA, American Express, Diners Club, CarteBlanche, Discover, EnRoute or JCB card.

isArray(value)

True if value is a JavaScript array object.

isBarcode(value)

True if value is a valid UPCA or EAN13 barcode number.

isBoolean(value)

True if value is a valid boolean value.

isByte(value)

True if value is a valid byte value (0-255).

isCB(value)

True if value is a valid format for a CarteBlanche credit card.

isCC(value)

True if value is a valid credit card number according to the mod 10 checksum.

isChecked(formFieldObject)

True if formFieldObject is checked. If formFieldObject is a group, returns number of checked items. formFieldObject must be a checkbox or radio button object.

isCookies()

True if cookie are enabled in browser. Can also be evaluated for type of cookies enabled: returns '1' if only session cookies are enabled and '2' if both session and persistent cookies are enabled.

isDate(value)

True if value is either 1) a date object, or 2) a date or time string that can be converted to a valid date object using dateParse() function.

isDateRange(value,date1,date2[,datepart])

True if value is a valid date within range of date1 and date2 (inclusive). datepart sets the precision of the comparison. Default is to the second.

Datepart     Description
s seconds
n minutes
h hours
d days
m months
yyyy years

isDateString(value)

True if value is a string in any valid date string format. Any value which returns true can be converted to a date object using dateParse() function.

isDay(value)

True if value is a 1 or 2 character integer between 1 and 31.

isDC(value)

True if value is a valid format for a Diners Club credit card.

isDec(value)

True if value is a valid decimal number. Decimal cannot be the last character. value can be signed or unsigned.

isDecRange(value,number1,number2)

True if value is a valid decimal number within range of number1 and number2 (inclusive).

isDISC(value)

True if value is a valid format for a Discover credit card.

isDomain(value)

True if value is a valid Generic Top-Level Domain according to IANA (.com, .edu, etc) or a two-letter string format for Country Code Top-Level Domain (.de, .au, etc.) Does not validate that ccTLD exists.

isDSTZ()

True if host system uses Daylight Saving Time.

isEAN13(value)

True if value is a valid format for an EAN13 barcode.

isEmail(value[,bCommon])

True if value is a properly formatted email address according to RFC 3696. Accepts escaped local parts and bracketed IP addresses. Accepts but does not validate existence of two-letter TLDs. Does not validate that email account actually exists. If bCommon is true, validates "common" email addresses, where the part to the left of the @ sign can only contain alphanumerics, periods, hyphens and underscores. Default bCommon is false.

isER(value)

True if value is a valid format for an EnRoute credit card.

isFEIN(value)

True if value is a valid Federal Employer Identification Number format ("xx xxxxxxx", "xx-xxxxxxx" or "xxxxxxxxx").

isGUID(value)

True if value is a valid Universally Unique Identifier format ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"). "x" must be a hexadecimal number.

isHMS(hours,minutes,seconds)

True if hours, minutes and seconds will create a valid time.

isHour(value)

True if value is a 1 or 2 character integer between 0 and 23.

isInt(value)

True if value is a valid integer. value can be signed or unsigned.

isIntGT(value,number)

True if value is a valid integer greater than number. value can be signed or unsigned.

isIntRange(value,number1,number2)

True if value is a valid integer within range of number1 and number2 (inclusive).

isIP(value)

True if value is a valid IP address. Does not validate that IP address exists.

isJCB(value)

True if value is a valid format for a JCB credit card.

isMC(value)

True if value is a valid format for a Mastercard credit card.

isMinute(value)

True if value is a 1 or 2 character integer between 0 and 59.

isMonth(value)

True if value is a 1 or 2 character integer between 1 and 12.

isNumberRange(value,number1,number2)

True if value is an integer or decimal number within range of number1 and number2 (inclusive).

isNumeric(value)

True if value is a numeric (ie, decimal or integer) value.

isObj(value)

True if value is a JS object (uses 'typeof' operator).

isPort(value)

True if value is a 1 to 5 character integer between 1 and 65535.

isSecond(value)

True if value is a 1 or 2 character integer between 0 and 59.

isSignedDec(value)

True if value is a signed decimal number.

isSignedInt(value)

True if value is a signed integer.

isSignedNumber(value)

True if value is a signed integer or decimal number.

isSSN(value)

True if value is a valid Social Security Number format ("xxx xx xxxx", "xxx-xx-xxxx" or "xxxxxxxxx").

isTimeString(value)

True if value is a string in any valid time string format. Any value which returns true can be converted to a date object using dateParse() function.

isUPCA(value)

True if value is a valid format for a UPCA barcode.

isUSPhone(value)

True if value is a valid U.S. telephone number format according to NANPA ("(xxx) xxx-xxxx" or "xxx-xxx-xxxx".) Can include U.S. country code prefix. Does not validate that telephone number exists.

isUUID(value)

True if value is a valid ColdFusion Universally Unique Identifier format ("xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx"). "x" must be a hexadecimal number.

isVISA(value)

True if value is a valid format for a VISA credit card.

isWhitespace(value)

True if value is not null and contains only whitespace characters (spaces, tabs, carriage returns, newlines and vertical tabs.)

isYear(value)

True if value is a 4 character integer greater than (or equal to) 1000.

isYMD(year,month,day)

True if year, month and day will create a valid date.

isZIP(value)

True if value is a valid format for a 5- or 9-digit U.S. ZIP Code ("xxxxx" or "xxxxx-xxxx".) Does not validate that ZIP Code exists.


Top · Validation Functions · Transform/Create Functions · Evaluation Functions · Action Functions

Action Functions

These functions do not return anything.

setCheckbox(Checkbox,State)

Sets CHECKED property of a checkbox or group of checkboxes.

Checkbox
Required. Object. Target checkbox or checkboxes.

State
Required. Boolean. Checkbox state. TRUE for checked, FALSE for unchecked.

setCookie(Name,Value[,Expires,Domain,Secure])

Sets a cookie on the client browser.

Name
Required. String. Name of cookie.

Value
Required. String. Value of cookie.

Expires
Optional. Integer. Number of days until cookie expires. Set to zero to delete the cookie. Default is session cookie (expires when browser is closed).

Domain
Optional. String. Domain for cookie. Default is host cookie.

Secure
Optional. Boolean. Only transmits cookie if the connection is secure. Default is FALSE.

setDisabled(Element,State)

Enables or disables a DOM element using "disabled" property.

Element
Required. Object or String. Target DOM element. Accepts either an object reference or the ID string.

State
Required. Boolean. Parameter value for "disabled".

setDisplay(Element[,Value])

Hides or unhides a DOM element using "style.display". Hidden elements are removed from the layout of the page and other elements will "flow" into the space.

Element
Required. Object or String. Target DOM element. Accepts either an object reference or the ID string.

Value
Optional. String. Parameter value for "style.display". Can be any valid value but most common are None, Inline, or Block. If omitted, this function acts as a toggle between None and Block.

setOption(SelectList,Value[,Target])

Selects an option in a select list by matching the value or label string.

SelectList
Required. Object or String. Object reference or ID string for select list.

ValueRequired. String. String to match. Match is case-sensitive.

TargetOptional. String. Perform match against value ("V") or label ("L"). Default is "V".

setVisible(Element[,Value])

Hides or unhides a DOM element using "style.visibility". Hidden elements still occupy the same place in the layout of the page.

Element
Required. Object or String. Target DOM element. Accepts either an object reference or the ID string.

Value
Optional. Boolean. TRUE for unhide, FALSE for hide. If omitted, this function acts as a toggle between hide and unhide.


Site last updated: 11 March 2012