dd-MMM-yyyy HH的常规表达:mm ...? [英] Regular Expresion for dd-MMM-yyyy HH:mm ...?

查看:339
本文介绍了dd-MMM-yyyy HH的常规表达:mm ...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框和一个MaskedEditExtender附加该文本框用于在此格式中输入值,如dd-MMM-yyyy HH:mm ....

现在我想放一个RegularExpressionValidator验证该文本框.....





i就像这样......



 <   asp:TextBox     ID   =  TextBox9    runat   =  server   文本  ='  <% #Bind(  ABOVEROTARY表  {0:d-MMM-yyyy HH:mm}) %>' >  
< cc1:MaskedEditExtender ID = MaskedEditExtender4 runat = server ClearMaskOnLostFocus = 错误

CultureName = zh-CN -GB 掩码 = 99-LLL-9999 99:99 TargetControlID = TextBox9 UserDateFormat = DayMonthYear >

< asp:RegularExpressionValidator ID = < span class =code-keyword> RegularExpressionValidator2 runat = server ControlToValidate = < span class =code-keyword> TextBox9

ErrorMessage = 无效的日期时间 < span class =code-attribute>

< span class =code-attribute> ValidationGroup = GridViewBHAHistory

ValidationExpression =





现在我想要正则表达式验证我的输入.....



有效期如

 12-Oct-2011 22:34 
23-dec- 1988 02:09





或无效,如

 43-TTT -8888 88:98 
12-oct-2011 25:39







帮助我....

解决方案

我不会使用正则表达式:它很难做到正确,并处理适当月份的天数。

相反,看看使用DateTime.TryParseExact:

 DateTime dt; 
if (DateTime.TryParseExact( 12 -Oct-2011 22:34 dd-MMM-yyyy HH:mm,CultureInfo.InvariantCulture,DateTimeStyles.None, out dt))
{
Console.WriteLine(dt);
}


试试这个\d {2} / \d {2} / \d {4}转到正则表达式在这里写一个表达式:validate expression \d {2} / \d {2} / \d {4}



这将验证它为dd / mm / yyyy


为我的解决方案我做了这个正则表达式以验证此格式中的日期时间



 dd-MMM-yyyy HH:mm 





这是正则表达式使用



   ^(0?[1-9 ] | [12] [0-9] | 3 [01]) - (月|月| JAN | 2月| 2月| 2月| 3月| 3月| MAR |四月|四月|四月|可能会|五月|五月|六月|君| JUN |七月|七月| JUL |八月|八月| AUG |九月|九月| SEP |十月|十月|华侨城| 11月| 11月| 11月| 12月| 12月| DEC) - (19 | 20)\d\\ \\d\s([0-1] [0-9] | [2] [0-3]):([0-5] [0-9])

I have one textbox and also one MaskedEditExtender to attache with that text box for entering value in this formate like dd-MMM-yyyy HH:mm....
now i want to put one RegularExpressionValidator to validate that text box.....


i have put it like this...

<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("ABOVEROTARYTABLE", "{0:d-MMM-yyyy HH:mm}") %>'>
<cc1:MaskedEditExtender ID="MaskedEditExtender4"  runat="server" ClearMaskOnLostFocus="False"

    CultureName="en-GB" Mask="99-LLL-9999 99:99" TargetControlID="TextBox9" UserDateFormat="DayMonthYear">

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox9"

ErrorMessage="Invalid DateTime" 

 ValidationGroup="GridViewBHAHistory"

ValidationExpression=""



now i want regular expression to validate my input.....

Valid like

12-Oct-2011 22:34
23-dec-1988 02:09



or not valid like

43-TTT-8888 88:98
12-oct-2011 25:39




help me....

解决方案

I wouldn't use a Regex for this: it is too difficult to get it right, and handle the number of days in the appropriate month.
Instead, look at using DateTime.TryParseExact:

DateTime dt;
if (DateTime.TryParseExact("12-Oct-2011 22:34", "dd-MMM-yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
    {
    Console.WriteLine(dt);
    }


try this \d{2}/\d{2}/\d{4} go to the regular expression properties and in that write a expression in:validate expression \d{2}/\d{2}/\d{4}

this will validate it to dd/mm/yyyy


for my solution i made this regular expression to validate datetime in this formate

dd-MMM-yyyy HH:mm



this is the regular expression use

"^(0?[1-9]|[12][0-9]|3[01])-(jan|Jan|JAN|feb|Feb|FEB|mar|Mar|MAR|apr|Apr|APR|may|May|MAY|jun|Jun|JUN|jul|Jul|JUL|aug|Aug|AUG|sep|Sep|SEP|oct|Oct|OCT|nov|Nov|NOV|dec|Dec|DEC)-(19|20)\d\d\s([0-1][0-9]|[2][0-3]):([0-5][0-9])


这篇关于dd-MMM-yyyy HH的常规表达:mm ...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆