System.Text.RegularExpressions.Regex rex1 = new Regex( @"^((((1[6-9]|[2-9]/d)/d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]/d|3[01]))|(((1[6-9]|[2-9]/d)/d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]/d|30))|(((1[6-9]|[2-9]/d)/d{2})-0?2-(0?[1-9]|1/d|2[0-8]))|(((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$" ); //短日期型
使用时只需:
if( rex1.IsMatch( Request.Form["BuyDate"].Trim() ) == false )
{
Response.Write( "
<script language='javascript'>
alert('日期输入格式不正确!应为<2005-1-1>');
</script>" );
return;
}
博客展示了使用System.Text.RegularExpressions.Regex创建正则表达式来验证短日期型格式。给出了具体的正则表达式代码,还展示了使用时的判断逻辑,若输入日期格式不符合要求,会弹出提示框告知用户。
1658

被折叠的 条评论
为什么被折叠?



