tags:

views:

405

answers:

3

I'd just like to know if there's a function/way to restrict input to a textbot to a formatted type e.g. a user can only enter a date type into a textbox; or a function similar to to the C scanset that I can use to achieve the same functionality?

Thanks

+6  A: 

If you are writing a desktop app you could use the MaskedTextBox.

The MaskedTextBox class is an enhanced TextBox control that supports a declarative syntax for accepting or rejecting user input. Using the Mask property, you can specify the following input without writing any custom validation logic in your application:

  • Required input characters.

  • Optional input characters.

  • The type of input expected at a given position in the mask; for example, a digit, or an alphabetic or alphanumeric character.

  • Mask literals, or characters that should appear directly in the MaskedTextBox; for example, the hyphens (-) in a phone number, or the currency symbol in a price.

  • Special processing for input characters; for example, to convert alphabetic characters to uppercase.

Andrew Hare
Thank you for your answer.
Dark Star1
You could have also derived from TextBox and created your own custom textbox. I have done this on a few occassions to achieve a numeric textbox!
James
This is a WinForms control, so in WPF you would need to make your own custom one, as James said.
emddudley
+2  A: 

The tool that would work best in this scenario is the Masked Edit Textbox.

David in Dakota
A: 

There is no such functionality, unless you use NumericTextBox and DateTimePicker controls.

But as always, you can define your own controls and logic by overriding the default TextBox control.

pixel3cs
-1 The above answer shows that there is such functionality
emddudley