最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Allow only MMYYYY date format in asp.net textbox - Stack Overflow

programmeradmin7浏览0评论

I have a requirement where user should be allowed to enter only MM/YYYY date format (Ex: 12/2013) in asp textbox. And i want to achieve this through client side coding (not through code behind). Have been struggling for long time, any help is much appreciated.

I have a requirement where user should be allowed to enter only MM/YYYY date format (Ex: 12/2013) in asp textbox. And i want to achieve this through client side coding (not through code behind). Have been struggling for long time, any help is much appreciated.

Share Improve this question edited Jan 23, 2013 at 22:17 Praveen Mitta asked Jan 23, 2013 at 17:40 Praveen MittaPraveen Mitta 1,5182 gold badges29 silver badges49 bronze badges 7
  • Code? whathaveyoutried. Give us something here. – PitaJ Commented Jan 23, 2013 at 17:42
  • This means validating the input. At what point would you like to validate? For example, do you want to make sure that the user is conforming to the desired pattern as they input (so 'a' is rejected) or do you want to validate after the textbox has "lost focus" (generating a prompt)? – JDB Commented Jan 23, 2013 at 17:43
  • Doesn't jQuery UI have a Date Picker that does this? – CodeChimp Commented Jan 23, 2013 at 17:44
  • I want to validate while user is entering the input in the textbox. – Praveen Mitta Commented Jan 23, 2013 at 17:45
  • Validate meaning alerting them to the error, or preventing them from making the error in the first place? – Pat Burke Commented Jan 23, 2013 at 19:20
 |  Show 2 more ments

3 Answers 3

Reset to default 4

If the user is manually typing this, then you would want to use a jQuery Masking Plugin like this one: http://digitalbush./projects/masked-input-plugin/

This will enforce the format you wanted by simply saying: $(selector).mask("99/9999"); It will also add the slash in there for you automatically and only allow numeric characters.

If the you want a calendar widget, this solution can be bined nicely with the jQuery UI Datepicker which can also limit the user's input: http://jqueryui./datepicker/

use jQuery datepicker and change dateformat:

$( "#textbox" ).datepicker({"dateFormat", "dd/yy"});

Finally this worked out for me.

<asp:MaskedEditExtender ID="meeMonthYear" runat="server" 
     TargetControlID="txtMonthYear" Mask="99/9999" MaskType="None" 
     InputDirection="RightToLeft"></asp:MaskedEditExtender>
发布评论

评论列表(0)

  1. 暂无评论