Reputation: 2321
Hello my WinForm application has a textbox that will be used for a time value. I know how to load like the current time into the textbox, but say when a user enters a value, what is the best way to validate or format the number so I can attempt to Convert it to a TimeDate
value?
Example:
User enters something like 800
should be able to be converted to 8:00am
or 2354
should be 11:54pm
. Also if they enter an invalid time, like 9cdf83
or something, I need to check that this value is convertable to a time. If not, throw a warning. Is there a way to display a system clock to choose the time from like the dateTimePicker
?
Upvotes: 1
Views: 1115
Reputation: 434
you can place the textbox and a label beside it specifying the format like 8:00 AM and for validating it you can use custom validation and use a suitable regular expression as required for the validator and attach it to textbox.
But For conversion I thing you will have to code and check its validity.
Upvotes: 0
Reputation: 48568
For things like date and time which u want user to enter best is to use DateTimePicker bcoz n number of users will have n number of ideas to fill it. u can't go on checking each and every option.
Instead DateTimePicker will make user to enter through it only.
Upvotes: 2