Personal tools

Log in

Changes

From All n One's bxp software Wixi

Jump to: navigation, search

JavaScript - Time Validation function

970 bytes added, 03:11, 12 November 2014
Created page with "Here is a handy function for validating time. <syntaxhighlight lang="javascript"> function fn_ValidateTime(){ var strCDA_X_Field = document.getElementById('strCDA_X_Fiel..."
Here is a handy function for validating time.


<syntaxhighlight lang="javascript">
function fn_ValidateTime(){
var strCDA_X_Field = document.getElementById('strCDA_X_Field');
var strValue = strCDA_X_Field.value;
var aryTemp = [];
var blValid = true;

//if the time is 8 digits 00:00:00
if(strValue.length == 8){
//if there is a seim-colon at 2 and 5
if((strValue.indexOf(':') == 2) && (strValue.indexOf(':') == 5)){
aryTemp = strValue.split(':');
//Check each element to see if they are correct, hours can be up 99 but the rest must be less than or equal 59
if(aryTemp[0] <= 99){
if(aryTemp[1] <= 59){
if(aryTemp[2] <= 59){
blValid = true;
}
else{
blValid = false;
}
}
else{
blValid = false;
}
}
else{
blValid = false;
}
}
else{
blValid = false;
}
}
else{
blValid = false;
}

return blValid;
}

</syntaxhighlight>
7,528
edits