Home > Mobile >  Filtering WinForms Textbox inputs
Filtering WinForms Textbox inputs

Time:09-17

So, I have a textbox in my WinForms program, and I want the textbox to only allow answers with at least two dots, and starting with letter "N" or "M".

private void SaveText_Click(object sender, EventArgs e)
        {
            MainNotifs.Show(this, "Attached !");
            attachment = true;
        }

I want it to set value of "attachment" to true, only if value of the textbox passes the criteria above.

CodePudding user response:

string input = txtBox.Text;
            
if((input.StartsWith("N") || input.StartsWith("M")) && input.Count(c => c == '.') >= 2)
{
    attachment = true;
}
  • Related