4
How do I make so that in the date field, is not saved a date that has already passed, for example yesterday and in the time field is not typed an invalid time, for example 27:00, only the Brazilian time. Both fields are MaskedTextBox
.
Data Validation:
public static bool ValidaData(string maskdata)
{
DateTime resultado = DateTime.MinValue;
if (DateTime.TryParse("dd/MM/yyyy", out resultado))
return true;
return false;
Date check:
if (clnValidacoes.ValidaData(maskdata.Text) == false)
{
MessageBox.Show("Data Inválida!");
maskdata.Focus();
}
But every date I set gives "Invalid". In 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’re making a mistake on Interger.
I edited the question.
– enzo
These codes are random and do not make sense. What is your difficulty? What do you want to result from? Give details so we can help.
– Maniero
I have a validation class with the codes, okay? Inside the Save button encoding, I put another code that will verify (through the Validation class) if the entered data is valid. I’d like you to help me with this code, because I don’t know if it’s right. In the date validation, the user cannot put a date that has already passed (example: yesterday’s) and the time cannot put a different time than our Brazilian time (example:25:00).
– enzo
Did any of the answers below solve your problem? Do you think you can accept one of them? Check out the [tour] how to do this, if you still don’t know how to do it. This helps the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero