As I do so that in the date field, not saved a date that has passed, for example the one of yesterday and in the hour field do not enter an invalid time, for example 27:00, only the Brazilian hours. Both fields are MaskedTextBox
.
Date Validation:
public static bool ValidaData(string maskdata)
{
DateTime resultado = DateTime.MinValue;
if (DateTime.TryParse("dd/MM/yyyy", out resultado))
return true;
return false;
Date verification:
if (clnValidacoes.ValidaData(maskdata.Text) == false)
{
MessageBox.Show("Data Inválida!");
maskdata.Focus();
}
But every date I put gives "Invalid." On time validation:
public static bool ValidaHora(string maskhora)
{
String hora = "";
String[] hms = hora.split(":");
int horas = Integer.parseInt(hms[0]);
int segundos = Integer.parseInt(hms[2]);
int minutos = Integer.parseInt(hms[1]);
if (horas > 24)
{
return false;
}
else
{
return true;
}
}
}
}
You get an error in Interger.