斯特托时间和日期验证(01/20/2011 vs 01/2011)
01/20/2011 = January 20, 2011
01/2011 = January 2011
只应允许这两种格式!
i.e. 01/01/01/2011 = ERROR!
PHP:
$date = '01/20/2011';
//$date = '01/2011';
if(........format test........)//01/20/2011
{
if(...validation...)
{
echo date('F j, Y', strtotime($date));
}
}
else//01/2011
{
if(...validation...)
{
echo date('F Y', .....);
}
}
验证:
IF = 01/20/2011
- 第一部分应仅包含数字 01-12
- 第二部分应仅包含数字 01-31
- 第三部分应包含 4 个数字
IF = 01/2011
- 第一部分应仅包含数字 01-12
- 第二部分应包含 4 个数字
01/20/2011 = January 20, 2011
01/2011 = January 2011
Only these two formats should be allowed!
i.e. 01/01/01/2011 = ERROR!
PHP:
$date = '01/20/2011';
//$date = '01/2011';
if(........format test........)//01/20/2011
{
if(...validation...)
{
echo date('F j, Y', strtotime($date));
}
}
else//01/2011
{
if(...validation...)
{
echo date('F Y', .....);
}
}
Validation:
IF = 01/20/2011
- First part should only contain numbers 01-12
- Second part should only contain numbers 01-31
- Third part should consist of 4 numbers
IF = 01/2011
- First part should only contain numbers 01-12
- Second part should consist of 4 numbers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这行得通吗:
Would this work: