设置日期和时间根据文化,将正则表达式表达为RegularExpressionValidator [英] set Date & time regular expression to RegularExpressionValidator according to culture

查看:102
本文介绍了设置日期和时间根据文化,将正则表达式表达为RegularExpressionValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临验证日期和问题的问题。根据当地文化的时间。



这是我的RegularExpressionValidator



 < asp:RegularExpressionValidator 
ID = regTime
ControlToValidate = txtTime
Display = 动态
Text = 无效的时间格式
ValidationExpression = ^((1 [012])|(0?[1 -9])):( [0-5] [0-9])?([aApP] [mM])$
runat = server >
< / asp:RegularExpressionValidator >





以上验证器验证了en-en文化的时间。



现在,当我开发一个需要能够处理每种文化的日期和时间格式的应用程序时,我想要一个如何验证日期和时间的具体解决方案。时间取决于使用RegularExpression的文化。



例如,美国时间格式为h:mm tt(01:20 PM)&德语时间格式为HH:mm(13:20)。

解决方案


runat = server >
< / asp:RegularExpressionValidator >





上述验证器验证了en-en文化的时间。



现在我正在开发一个应用程序需要能够处理每种文化的日期和时间格式,我想要一个具体的解决方案,如何使用RegularExpression根据文化验证日期和时间。



For例如,美国时间格式为h:mm tt(01:20 PM)&德国时间格式为HH:mm(13:20)。


尝试此验证表达式



 @^(([0-2] \d | [3] [0-1])\。([0] \ d |。[1] [0-2])\ [2] [0] \d {2}) 


I am facing a problem of validating date & time according to local culture.

This is my RegularExpressionValidator

<asp:RegularExpressionValidator
       ID="regTime"
       ControlToValidate="txtTime"
       Display="Dynamic"
       Text="Invalid Time Format"
       ValidationExpression="^((1[012])|(0?[1-9])):([0-5][0-9]) ?([aApP][mM])$"
       runat="server">
 </asp:RegularExpressionValidator>



The above validator validates time of en-en culture.

Now as I am developing an applications which needs to be able to handle date and time format of every culture, I want a concrete solution to how to validate date & time depending on culture using RegularExpression.

For example, American time format is h:mm tt (01:20 PM) & German time format is HH:mm (13:20).

解决方案

" runat="server"> </asp:RegularExpressionValidator>



The above validator validates time of en-en culture.

Now as I am developing an applications which needs to be able to handle date and time format of every culture, I want a concrete solution to how to validate date & time depending on culture using RegularExpression.

For example, American time format is h:mm tt (01:20 PM) & German time format is HH:mm (13:20).


try this Validation expression

@"^(([0-2]\d|[3][0-1])\.([0]\d|[1][0-2])\.[2][0]\d{2})


"


这篇关于设置日期和时间根据文化,将正则表达式表达为RegularExpressionValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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