Formatting a text field in MM / YYYY

I have a text box in my web forms (ASP.NET Web Forms) that I want to display something like this:

MM / YYYY

I want this "/" to be in the middle when the user enters the month and year. How to do it in C #?

+4
source share
4 answers

Take a look at the MaskedTextbox class (for Windows Forms anyway ... I see that you have now specified it as Web Forms).

+3
source

I would look at the jQuery plugin for nested input:

https://plugins.jquery.com/maskedinput/

It seems like this is perfect for what you need to do.

The implementation is as follows:

jQuery(function($){ $("#date").mask("99/99/9999"); $("#phone").mask("(999) 999-9999"); $("#tin").mask("99-9999999"); $("#ssn").mask("999-99-9999"); }); 

Here you can see the demo:

http://digitalbush.com/projects/masked-input-plugin/

+5
source

If you are using Windows Forms, check out the MaskedTextBox class. If you are using WPF, look at the FilteredTextBox or possibly MaskedTextBox . If WebForms is ASP.NET, there are other options, such as a masked text field or various jquery features.

+2
source

We will use a date control that supports the selection of the month / year OR split the field into two separate fields, one month for the other throughout the year.

For a web application, it's usually best to just split it up. That way you cover most of the possibilities.

If you insist on keeping it in one field and donโ€™t want to use a specially designed control, then donโ€™t worry about the oblique line and parse as soon as the field is published ... But this should be the last resort.

0
source

All Articles