普通防爆pression日期和时间 [英] Regular Expression Date and Time

查看:128
本文介绍了普通防爆pression日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人您好我有以下的前preSS验证

Hi people I have the following express validation

    [Required]
    [RegularExpression("{0:d/M/yyyy HH:mm:ss}" , 
    ErrorMessage = "Wrong Syntax")]
    public string Posted { get; set; }` 

但是它不允许以下输入其中正在显示日期和时间的一个例子:
12/12/2011 00:00:00(我不希望这些确切的数字的日期和时间,应该允许它按日期和时间标准逻辑允许任何数字)

But it does not allow the following input which am showing as a example of date and time: 12/12/2011 00:00:00 (I do not want these exact numbers the date and time should allow any numbers which is allowed logically by date and time standards)

我收到错误消息语法错误,甚至当我输入正确的code。似乎是什么的问题。任何帮助将是非常美联社preciated太谢谢你了。

I get the error message "Wrong Syntax" even when i input the correct code. What seems to be the problem. Any help will be really appreciated Thank You So Much

推荐答案

这是因为 RegularEx pressionAttribute 需要一个正则表达式模式,您提供一个.NET字符串格式模式( MSDN:RegularEx pressionAttribute类)。

It is because RegularExpressionAttribute expects a Regex pattern and you are providing a .NET string format pattern (MSDN: RegularExpressionAttribute Class).

对于基本格式验证你需要使用这样的:

For basic format validation you would need to use something like:

[RegularExpression(@"\d{2,2}/\d{2,2}/\d{4,4} \d{2,2}:\d{2,2}:\d{2,2}")]

这篇关于普通防爆pression日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆