Validating user input in C# coming from XAML controls I have page where I am inserting some data into Entry fields. For each Entry I have written in XAML different controls with parameters. One of them is Formated parameter where I am giving a string which I am checking on C# logic code. The problem which I figure out that some one could insert wrong string or string but for example with lower case. How can I improve this code for any wrong input scenarios ? 

This is my xaml code:

&lt;ContentPage.Content&gt;

    &lt;StackLayout Padding="7,7,7,7" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Spacing="0"&gt;

      &lt;cv:LabelEntryView x:Name="Name" LabelText="some text 4" ColorBg="White" MaxLength="20" Placeholder="some text 4" Formated="NameValidation" Keyboard="Text" &gt;
      &lt;/cv:LabelEntryView&gt;

      &lt;cv:LabelEntryView x:Name="CardNr" LabelText="some text 3" ColorBg="White" MaxLength="20" Placeholder="some text 3" Formated="CardNrValidation" Keyboard="Numeric"  &gt;
      &lt;/cv:LabelEntryView&gt;

      &lt;cv:LabelEntryView x:Name="ExpDate" LabelText="some text 2" ColorBg="White" MaxLength="5" Placeholder="some text 2" Formated="ExpDate" Keyboard="Numeric" &gt;
      &lt;/cv:LabelEntryView&gt;

      &lt;cv:LabelEntryView x:Name="SecurNr" LabelText="some text" ColorBg="White" MaxLength="3" Placeholder="some text" Keyboard="Numeric" &gt;
      &lt;/cv:LabelEntryView&gt;

    &lt;/StackLayout&gt;

  &lt;/ContentPage.Content&gt;


and here is my C# code with if statement checking string:

private void Entry_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (Formated == "NameValidation")
            {
                Entry ent = (Entry)sender;
                ToUpper(ent);
            }
            else if (Formated == "CardNrValidation")
            {
                Entry ent = (Entry)sender;
                CardNumberValidation(ent);
            }
            else if (Formated == "ExpDate")
            {
                Entry ent = (Entry)sender;
                ExpDate(ent,e);
            }
}


Maybe I have to assign type for each if check? If yes, how can I do it?
Thank you for your reviews.
This is not how it should be done in WPF especially that you are not validating the text but just changing it upper case - you validate only the numeric input.

The right way would be to use the Binding Validation

This method would allow you to write specialized validators without ifs or switches.