Validasi [ Numeric & Alfanumeric] di Textbox dengan CSharp (C#)

Validasi Textbox dengan C#

Berikut Code Validasi  Angka dan huruf di C#

public string Numeric = "0123456789\b";
public string AlfaNumeric = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789";
//string bisa di ganti sesuai dengan kebutuhan validasi
public int ValidasiText(char c, string AllowedChar)
{
   return AllowedChar.IndexOf(c);
}
Masukin Fungsi di atas ke textbox Event (TextKeyPress) dengan code :
private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
{
  if(ValidasiText(e.KeyChar,Fungsi.Numeric) == -1)
  {
    e.Handled = true;
  }
}
Previous
This is the oldest page
Thanks for your comment