You are on page 1of 1

Como validar un Cuadro de texto(TextBox) para que solo acepte nmeros

MC. Fernando Campos Camacho -UdeO GML-

// Debe agregar la referencia using System.Text.RegularExpressions;

// funcin necesaria public static bool EsNumero(string num) { Regex patron = new Regex(@"^(\d|-)?(\d|,)*\.?\d*$"); return patron.IsMatch(num); }

// ponga el cdigo en un textbox private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (EsNumero(textBox2.Text)) { MessageBox.Show("Todo Bien"); } else MessageBox.Show("Solo se aceptan nmeros"); } }

Oct, 2013

You might also like