普通防爆pression验证日期格式DD / MMM / YYYY [英] Regular Expression validator for date format DD/MMM/YYYY

查看:298
本文介绍了普通防爆pression验证日期格式DD / MMM / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:TextBox ID="txtDob" runat="server" MaxLength="100" CssClass="textbox2" size="10"  />
<ajax:TextBoxWatermarkExtender ID="txtWEDOB" WatermarkText="DD/MON/YYYY" TargetControlID="txtDob" runat="server" />
<asp:RegularExpressionValidator ID="rfv" runat="server" ControlToValidate="txtDob" SetFocusOnError="true" 
ValidationExpression="^(3[0-1]|2[0-9]|1[0-9]|0[1-9])[\s{1}|\/|-](Jan|JAN|Feb|FEB|Mar|MAR|Apr|APR|May|MAY|Jun|JUN|Jul|JUL|Aug|AUG|Sep|SEP|Oct|OCT|Nov|NOV|Dec|DEC)[\s{1}|\/|-]\d{4}$"  
Display="None" ValidationGroup="search" ErrorMessage="Please enter correct date">
</asp:RegularExpressionValidator>

我用这普通的前pression验证日期。它不给错误像12-FEB-2010或2月12日2010年我公司严格要12 / FEB / 2010格式。在这个普通的前pressii \不工作的时间像29 / FEB / 2010。什么样的变化需要作出的。

I am using this regular expression validator for date. It is not giving error for like 12-FEB-2010 or 12 Feb 2010. I strictly want 12/FEB/2010 format. This Regular expressii\on is not working for date like 29/FEB/2010. what changes need to be made.

推荐答案

这将是非常复杂的正前pression如果您想验证所有可能的情况下(例如像30 / FEB)。

It will be very complicated regular expression if you want to validate all the possible cases (like for example 30/FEB).

您将需要分前pression几个月30天,你将需要一个子前pression数月31日,最有意思的是二月和闰年。我不认为用一个普通的前pression是一个好主意在这里。

You will need sub-expression for months with 30 day, you will need a sub-expression for months with 31 day, and the most interesting is Feb and leap years. I don't think that using a regular expression is a good idea here.

要在注释的问题:

^((31(?! (FEB|APR|JUN|SEP|NOV)))|((30|29)(?! FEB))|(29(?= FEB (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])/(JAN|FEB|MAR|MAY|APR|JUL|JUN|AUG|OCT|SEP|NOV|DEC)/((1[6-9]|[2-9]\d)\d{2})$

这篇关于普通防爆pression验证日期格式DD / MMM / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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