Validating input for a text field in C # Winforms

I am trying to verify that input to a text box on winforms C # matches a valid pattern.

The pattern must be a string of only the following characters

  • 0 to 9
  • from A to Z
  • "-"
  • "/"

I am considering using the Validation event in a text box to perform validation, but I am struggling with the correct regular expression to use - or maybe better than using a regular expression.

+3
source share
2 answers

"[A-Z0-9_/]" . Regex ( ), .

'\' . , "[a-zA-Z0-9 _/]".

- "(\ w?\d? _?/?) +" -\w , \d . "?" char 0 1 , + .

+3

KeyDown TextBox SuppressKeyPress KeyEventArgs true, , . , , KeyCode KeyEventArgs. , , , , .

+1

Source: https://habr.com/ru/post/1758473/


All Articles