gpt4 book ai didi

c# - 如何为日期格式 MM/DD/YYYY HH :MM:SS am/pm in ASP. NET 应用正则表达式

转载 作者:行者123 更新时间:2023-11-30 17:43:20 24 4
gpt4 key购买 nike

我有一个文本框,我以 dd/mm/yyyy hh:mm:ss 的身份从用户那里获取输入。现在,我想用正则表达式验证它。我不确定如何应用该表达式。我也附上了我的代码。

  <tr>
<td style="width: 30%" class="EcommLabel">
Date From
</td>
<td style="width: 70%" class="EcommLabel">
<asp:TextBox ID="txtDateFrom" CssClass="EcommNormalTextBox" runat="server">
</asp:TextBox>MM/DD/YYYY<br />

<%-- <asp:RegularExpressionValidator ID="regDateFrom" ValidationExpression="^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$" ControlToValidate="txtDateFrom" ValidationGroup="Promotion" runat="server" ErrorMessage="Invalid Date"></asp:RegularExpressionValidator>--%>

<asp:RangeValidator runat="server" ID="rvDateFrom" Type="Date" ControlToValidate="txtDateFrom" MaximumValue="3000/12/31" MinimumValue="2000/1/1" ErrorMessage="Invalid Date" Display="Dynamic" ValidationGroup="Promotion" />
</td>
</tr>

最佳答案

使用这个表达式 "(\d{2}):(\d{2}):(\d{4}):(\d{2}):(\d{2}):(\d {2})”喜欢

<asp:RegularExpressionValidator ID="regDateFrom" ValidationExpression="(\d{2}):(\d{2}):(\d{4}):(\d{2}):(\d{2}):(\d{2})"
ControlToValidate="txtDateFrom" ValidationGroup="Promotion" runat="server"
ErrorMessage="Invalid Date"></asp:RegularExpressionValidator>

另请参阅以下 stackoverflow 问题:
How to write a regex for MM:DD:YYYY:HH:MM:SS
MM/DD/YYYY HH:MM:SS AM/PM date validation regular expression in javascript

希望对您有所帮助!

关于c# - 如何为日期格式 MM/DD/YYYY HH :MM:SS am/pm in ASP. NET 应用正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com