isTime(time [, formatOption])
Last updated March 4, 2010
Version: 0 | Requires: ColdFusion MX | Library: DateLib
Description:
Validates if a string is a valid time in 12- or 24-hour format. Optionally, can require time be in a specific format.
Return Values:
Returns a boolean.
Example:
isTime("1:23:45 pm", "12")<br />
isTime("23:00")<br />
isTime("23:00:00", "24")
Parameters:
| Name | Description | Required |
|---|---|---|
| time | time string to check format | Yes |
| formatOption | argument to check if 12 or 24 hr format required | No |
Full UDF Source:
<cfscript>
/**
* Validates if a string is a valid time in 12- or 24-hour format
*
* @param time time string to check format (Required)
* @param formatOption argument to check if 12 or 24 hr format required (Optional)
* @return Returns a boolean.
* @author Mosh Teitelbaum (mosh.teitelbaum@evoch.com)
* @version 0, March 4, 2010
*/
function isTime(time) {
var found=0;
if ( (arrayLen(arguments) eq 2) AND (arguments[2] is "12")) {
found=reFindNoCase("^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [ap]m))$", arguments.time);
} else if ( (arrayLen(Arguments) eq 2) AND (Arguments[2] is "24")) {
found=reFindNoCase("^([01]\d|2[0-3])(:[0-5]\d){0,2}$", arguments.time);
} else {
found=reFindNoCase("^([01]\d|2[0-3])(:[0-5]\d){0,2}$|^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [ap]m))$", arguments.time);
}
if (found GT 0)
return true;
else
return false;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
3 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)