Regular Expression -Date:MM/dd/yyyy,M/dd/yyyy

本文介绍了一个用于验证SQL Server中日期时间格式的有效正则表达式。该表达式支持带前导零的月份、日期及小时,并正确处理11小时的情况。此外,文章还提及了对于非闰年2月29日处理的限制。
Regular Expression Details

[ Find] [ Test]
Title
Pattern Title
Pattern
^(((((0[13578])|([13578])|(1[02]))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(3[01])))|((([469])|(11))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(30)))|((02|2)[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9]))))[\-\/\s]?\d{4})(\s(((0[1-9])|([1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$
Author
David Darling
Matching Text
11/30/2003 10:12:24 am|||2/29/2003 08:14:56 pm|||5/22/2003
Non-Matching Text
11/31/2003 10:12:24 am|||2/30/2003 08:14:56 pm|||5/22/2003 14:15
Description
Following expression can be used to validate a datetime column from SQL Server. This expression is an enhanced version of Scott Watermasysk's date/time submission. It now accepts leading zeros in months, days, and hours. In addition, this expression properly handles the 11th hour. Watermasysk's would take the 10th and 12th hour but not the 11th. This regex has been tweaked to do so. Does not handle the February 29th problem on non-leap years yet. Will learn a little more about RegEx and do so in later submission.
Source
 

转载于:https://www.cnblogs.com/neilvension/archive/2007/09/22/902321.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值