function validaHora(hora) {
if (hora.length == 0) {
return true;
}
if (hora.length != 8) {
return false;
}
if (hora.charAt(2) != ':' || hora.charAt(5) != ':') {
return false;
}
for (i = 0 ; i < hora.length ; i++) {
if (i != 2 && i != 5) {
if (isNaN(hora.charAt(i))) {
return false;
}
}
}
var h = hora.substring(0,2);
var m = hora.substring(3,5);
var s = hora.substring(6,8);
if (h > 23 || m > 59 || s > 59) {
return false;
}
return true;
}
########################################################################################
function Mascara_Hora(Hora){
var hora01 = '';
hora01 = hora01 + Hora;
if (hora01.length == 2){
hora01 = hora01 + ':';
document.forms[0].tx_hora.value = hora01;
}
if (hora01.length == 5){
Verifica_Hora();
}
}
function Verifica_Hora(){
hrs = (document.forms[0].tx_hora.value.substring(0,2));
min = (document.forms[0].tx_hora.value.substring(3,5));
estado = "";
if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){
alert('Hora no formato inválido!')
document.forms[0].tx_hora.focus();
return false;
}
if (document.forms[0].tx_hora.value == "") {
alert('Favor digite a hora!')
document.forms[0].tx_hora.focus();
return false;
}
return true;
}
Nenhum comentário:
Postar um comentário