Answer the question
In order to leave comments, you need to log in
How to implement input validation on button click?
I want to implement a validation of all input data in the registration fields and after clicking on the Registration button, so that all input data is checked for correctness in the method and then there is a transition to the Login form.
I have the correctness checks themselves, but I want to implement so that when you click on the button, data is entered if all the fields are correctly filled in and there is a transition to another form.
I tried to hack through a boolean variable, but the crutch did not pass
The project itself The project
is made on EF Core using MS Sql
Ps The code turned out to be too cumbersome and does not let it in here, because there are too many characters.
Answer the question
In order to leave comments, you need to log in
I want to implement validation of all input data in the registration fields and after clicking on the Registration buttonthe train of thought is clear, typical for a beginner.
Here is the solution for one of the boxes
public bool IsNameValid(string name)
{
bool valid = false;
Regex check = new Regex(@"^([A-Z][a-z-A-z]+)$");
valid = check.IsMatch(name);
if (valid == true)
{
return valid;
}
else
{
return valid;
}
}
private void nameBox_TextChanged(object sender, EventArgs e)
{
TextChange(sender, e);
}
private void nameBox_Validating(object sender, CancelEventArgs e)
{
if (!IsNameValid(nameBox.Text))
{
inputincorrect.SetError(nameBox, "Invalid name");
}
else
{
inputincorrect.SetError(nameBox, null);
}
}
if (IsNameValid(nameBox.Text) == true && // ещё проверки)
{
// какой-то код
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question