0
How could develop routine [code block], in order to treat the text field where to insert the Hours in real time (Current time, resulting at the moment). In case the user tries to add hours past - issue warning that he cannot enter time day.
For example:
If now they are 7:00 in the morning, the user will be able to put the 7:00, 7:01 am or 7:02 or plus, but never. introduce least.
This prevents the user(s) from) malicious and/or unsuspecting try to bypass the system - then it will sound like a:
alert('Horário inaceitável. Você atrasou seu danadinho! Insira a HORA atual. Quando chegar o dia do pagamento a gente conversar.rsrs')
Code
function Mascara_Hora(Hora){
var hora01 = '';
hora01 = hora01 + Hora;
if (hora01.length == 2){
hora01 = hora01 + ':';
document.forms[0].Hora.value = hora01;
}
if (hora01.length == 5){
Verifica_Hora();
}
}
function Verifica_Hora(){
hrs = (document.forms[0].Hora.value.substring(0,2));
min = (document.forms[0].Hora.value.substring(3,5));
estado = "";
if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){
estado = "errada";
}
if (document.forms[0].Hora.value == "") {
estado = "errada";
}
if (estado == "errada") {
alert("Hora inválida!");
document.forms[0].Hora.focus();
}
}
<input name="Hora" type="text" id="Hora" class="input_text" OnKeyUp="Mascara_Hora(this.value)" size="5" maxlength="5">
However almost ready only this logic remains [accept current time to validate], which I do not know yet.
Then the correct is to validate next to the server as well, because if the user disables the Javascript in the browser is gone.
– NoobSaibot
@wmsouza Actually what I want is an example, but this will be done on the server side same.
– Diego Henrique