string character checking
-
Hi, I'm doing a printing range option, allow user type the print range like in the Microsoft Word. for example, the range can be (1,2,4-8,10-12) now, I would like to do a validation, prevent any non-useful character inside this string (i.e. except digit, "," and "-") any faster way to do this? Thanks for your help.
-
Hi, I'm doing a printing range option, allow user type the print range like in the Microsoft Word. for example, the range can be (1,2,4-8,10-12) now, I would like to do a validation, prevent any non-useful character inside this string (i.e. except digit, "," and "-") any faster way to do this? Thanks for your help.
Yes, write a KeyPress event handler for the TextBox.
private void tbPages\_KeyPress ( object sender , System.Windows.Forms.KeyPressEventArgs e ) { if ( "0123456789,-\\b".IndexOf ( e.KeyChar ) == -1 ) { e.Handled = true ; } return ; }
(
\b
is backspace) -
Yes, write a KeyPress event handler for the TextBox.
private void tbPages\_KeyPress ( object sender , System.Windows.Forms.KeyPressEventArgs e ) { if ( "0123456789,-\\b".IndexOf ( e.KeyChar ) == -1 ) { e.Handled = true ; } return ; }
(
\b
is backspace)