开发者

Formatting Textbox into MM/YYYY

I have a textbox in m开发者_如何学JAVAy web forms (ASP.NET Web Forms) which I want to show something like this:

MM/YYYY

I want this "/" in the middle when user is entering the month and year. How should I do this on C#?


I would take a look at the Masked Input jQuery plugin:

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

Seems like it would fit nicely for what you need to do.

Implementation looks like this:

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

You can see demos here:

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


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


If you're using Windows Forms, take a look at the MaskedTextBox class. If you're using WPF, take a look at the FilteredTextBox or perhaps the MaskedTextBox control. If WebForms ASP.NET, there are some other options like this Masked Textbox or various jquery possibilities.


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

For a web app, it's usually better to just split it out. That way you cover the most possibilities.

If you insist on keeping it in one field and don't want to use a purpose built control, then don't worry about the slash and do some parsing once the field is posted... But this should be a last resort.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜