Home > .Net Framework > Validasi Angka di C#

Validasi Angka di C#


Terkadang ada form yang salah satu inputnya, misal TextBox hanya menerima angka, berikut caranya

public static void NumericTextBox(KeyPressEventArgs e)
        {
            string strValid = "0123456789";
            if (e.KeyChar == (char)56)
                e.Handled = false;
            else
            {

                if (strValid.IndexOf(e.KeyChar) < 0 && !(e.KeyChar == (char)Keys.Back))
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }
Categories: .Net Framework
  1. March 13, 2014 at 3:07 am

    kk ko backspacenya gk jadi ya. jika saya rubah hanya dapat menerima huruf

    • March 13, 2014 at 3:25 am

      Ditambah lagi karakter backspace dengan diambil asciinya

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: