i am using the following code to validate a time field in my application, however this only checks the correct characters are used and not in the correct order. Ideally i require validation that checks that the data entered is in the following order HH:MI, any suggestions appreciated
var checkOK = "0123456789:";
var checkStr = theForm.p_open_time.value;
var allValid = true;
var allNum = "";
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter a time in the format HH:MI.");
theForm.p_open_time.focus();
return false;
}
return true;
var checkOK = "0123456789:";
var checkStr = theForm.p_open_time.value;
var allValid = true;
var allNum = "";
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter a time in the format HH:MI.");
theForm.p_open_time.focus();
return false;
}
return true;