Showing posts with label ake a text box only to accept digits. Show all posts
Showing posts with label ake a text box only to accept digits. Show all posts

Jan 5, 2014

C# Make A TextBox Accept Only 1 (. or ,) with Digits

  • You First Have To Go To The Properties Of The Textbox And Find For The Event Keypress And Double Click The Event Then You Will Get A New Event Like Below ..


         private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
             {
            
              }


  • Now All You Have To Copy The Code Below And Paste It Inside The Event Function...


            if (!char.IsControl(e.KeyChar)
                    && !char.IsDigit(e.KeyChar)
                    && e.KeyChar != '.')
            {
                e.Handled = true;
            }
            // only allow one decimal point
            if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }

----------------------------------------------------------------------------------------------------------------------------------
           // only allow one coma
            if (e.KeyChar == ',' && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }

  • And It Should Look Like This .. When Done.. 

            private void textbox1_KeyPress(object sender, KeyPressEventArgs e)

                {

                    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)&& e.KeyChar != '.')
                      {
                           e.Handled = true;
                      }

                      // only allow one decimal point
                      if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
                     {
                         e.Handled = true;
                         }

                 }

C# Make A TextBox Accept Only Numeric Values


  • You First Have To Go To The Properties Of The Textbox And Find For The Event Keypress And Double Click The Event Then You Will Get A New Event Like Below ..


         private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
             {
            
              }


  • Now All You Have To Copy The Code Below And Paste It Inside The Event Function...


            char keypress = e.KeyChar;
            if (char.IsDigit(keypress) || e.KeyChar == Convert.ToChar(Keys.Back))
            {
                //eventChecker("T");
            }
            else
            {
                e.Handled = true;
            }

  • And It Should Look Like This .. When Done.. 

            private void textbox1_KeyPress(object sender, KeyPressEventArgs e)

                {
                    char keypress = e.KeyChar;
                    if (char.IsDigit(keypress) || e.KeyChar == Convert.ToChar(Keys.Back))
                    {
                          //eventChecker("T");
                     }
                         else
                         {
                               e.Handled = true;
                         }

                 }
     

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...