惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - 沐枫

git+svn 中文文件名乱码的处理 发展国产基础软件以及反盗版的异想 Mvc 2.0 Preview2 中 DefaultParameterValue 不支持枚举的Bug DynamicControl/DynamicField 例外的解决 推荐一个不错的flex ajax javascript资源网站 .net winform 的 OnKeyDown 与 方向键 MySQL 5.1 无法创建、修改存储过程的解决(简单问题) 一个稍微好用些的 svn 服务器 VC中的一个很奇怪的问题--关于C4244 汉语编程++ 关于Array.IndexOf 从赋值到初始化 从for到foreach 关注C++0x: Concept Ultimate Toolbox 开源了 关于C#2.0编译器的一个瘕疵 VC2008 beta2 的几个新东西 C++指针探讨 (四) 函数对象 boost 1.34 终于简化了内嵌python的支持
ASP.NET 日期数据服务端验证失败的原因
沐枫 · 2009-11-11 · via 博客园 - 沐枫

   Mvc 2.0 Preview2 增加了客户端验证的功能,但实际使用中,有同事发现正则表达式验证日期输入时,客户端验证成功,而服务端验证总失败。

   检查同事的代码,并没有发现明显的问题:(注,此处正则表达式经过简化)

[RegularExpression("^20\d\d-\d?\d-\d\d$")]
object somedate {get;set;}

  运行,在文本框中输入 2009-12-30 ,服务端提示正则表达式匹配失败。

  不解,反编译RegularExpressionAttribute,其中IsValidate代码如下:

public override bool IsValid(object value)
{
    
string str = Convert.ToString(value, CultureInfo.CurrentCulture);
    
if (string.IsNullOrEmpty(str))
    {
        
return true;
    }
    Match match 
= this.Regex.Match(str);
    
return ((match.Success && (match.Index == 0)) && (match.Length == str.Length));
}

  终于发现问题,原来,日期数据被Convert.ToString后,生成的日期是带时间的,如:2009-12-30 0:00:00,所以正则匹配总是失败。因此,匹配日期的时候,应该为正则表达式留出时间数据的位置。这一点,WebForm和Mvc都是一致的。