Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if a "." has been input into a TextBox?
    primarykey
    data
    text
    <p>How to check if a "." has been input into a TextBox?</p> <p>is it something like:</p> <pre><code>if (TextBox1.Text == ".") { //Do something... } </code></pre> <p>because when I do this, it seems to not check what is in the TextBox1 and just continue with the next line of code</p> <p>Here is my code:</p> <pre><code>private void btnContinue1_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(HouseholdNoTextBox.Text)) { textBlockError2.Visibility = Visibility.Collapsed; textBlockError1.Visibility = Visibility.Visible; } if (HouseholdNoTextBox.Text.Length &gt;= 3) {//checking to see if it has a length greater than 2 textBlockError1.Visibility = Visibility.Collapsed; // collapse the first error box if it is visible textBlockError2.Visibility = Visibility.Visible; // and make visible the second } if (HouseholdNoTextBox.Text == ".") { textBlockError1.Visibility = Visibility.Visible; } if (HouseholdNoTextBox.Text.Length &lt;= 2 &amp;&amp; HouseholdNoTextBox.Text.Length &gt; 0) { textBlockError1.Visibility = Visibility.Collapsed; textBlockError2.Visibility = Visibility.Collapsed; NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } </code></pre> <p>I have also tried:</p> <pre><code>if (HouseholdNoTextBox.Text.Contains(".")) { textBlockError1.Visibility = Visibility.Visible; } </code></pre> <p>I have also tried:</p> <pre><code>private void btnContinue1_Click(object sender, RoutedEventArgs e) { string houseHoldNo = HouseholdNoTextBox.Text.ToString(); if (string.IsNullOrEmpty(HouseholdNoTextBox.Text) || houseHoldNo.Contains(".")) // adding it here along with the first if statement { textBlockError2.Visibility = Visibility.Collapsed; textBlockError1.Visibility = Visibility.Visible; } } </code></pre> <p>I have also tried:</p> <p>private void btnContinue1_Click(object sender, RoutedEventArgs e) { string houseHoldNo = HouseholdNoTextBox.Text.ToString();</p> <pre><code> if (string.IsNullOrEmpty(HouseholdNoTextBox.Text)) { textBlockError2.Visibility = Visibility.Collapsed; textBlockError1.Visibility = Visibility.Visible; } if (houseHoldNo.Contains(".")) { textBlockError1.Visibility = Visibility.Visible; } } </code></pre> <p>and this above code does the same as the other.. it skips to the last if statement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload