日期验证一个TextBox [英] Date validation for a textbox
本文介绍了日期验证一个TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用该功能拍摄日期毫米/ dd / yyyy格式...
I have been using this to take date as mm/dd/yyyy format...
<asp:CompareValidator ErrorMessage="(mm/dd/yyyy)" Display="Dynamic" ID="valcDate"
ControlToValidate="txtDob" Operator="DataTypeCheck" Type="Date"
runat="server"></asp:CompareValidator>
<asp:RangeValidator ID="valrDate" runat="server" ControlToValidate="txtDob"
MinimumValue="12/31/1950"
MaximumValue="1/1/2100" Type="Date" Text="Invalid Date" Display="Dynamic" />
但它走的是两位数的年份也...
PLZ建议
but it is taking the two digit year also... plz suggest
推荐答案
您可能希望使用一个普通的前pression的日期:
You might want to use a regular expression for the date :
<asp:RegularExpressionValidator ID="dateValRegex" runat="server" ControlToValidate="txtDob" ErrorMessage="Please Enter a valid date in the format (mm/dd/yyyy)" ValidationExpression="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"></asp:RegularExpressionValidator>
此外,由于丹尼尔指出下面你将需要结合使用这与其他验证,充分验证日期。
Also, as Daniel pointed out below you will need to use this in conjunction with your other validators to fully validate the date.
这篇关于日期验证一个TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文